当我的页面继承自 PhoneApplicationPage 时,WP7 Silverlight 工具包日期选择器引发空引用异常

发布于 2024-11-30 17:57:53 字数 2290 浏览 1 评论 0原文

当我使用从 PhoneApplicationPage 继承的自定义页面而不是直接使用它时,日期选择器会抛出 null ref 异常...

我的自定义类:

public class CustomPhoneApplicationPage : PhoneApplicationPage
{
  public CustomPhoneApplicationPage()
  {
      Loaded += CustomPhoneApplicationPageLoaded;
      IsAnimFromDisabled = false;
      IsAnimToDisabled = false;
      this.Tap += CustomPhoneApplicationPageTap;
      InitTransition();
  }
  private void InitTransition()
  {
    RenderTransform = new CompositeTransform();
    _comeInStoryboard = Application.Current.Resources["FadeIn"] as Storyboard;
    _comeOutStoryboard = Application.Current.Resources["FadeOut"] as Storyboard;
    Debug.Assert(_comeInStoryboard != null, "_comeInStoryboard != null");
    Debug.Assert(_comeOutStoryboard != null, "_comeOutStoryboard != null");
  }
}

在 Xaml 中使用日期选择器:

<toolkit:DatePicker x:Name="_dateTimePicker" Value="{Binding SnapshotTime, Mode=TwoWay}" />

此处抛出异常:

Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.DataSource.GetPrevious(对象relativeTo)+ 0x7字节

以下是我如何使用此类作为应用程序中页面的基础:

public partial class AddOrEditData : CustomPhoneApplicationPage
{


    public AddOrEditData()
    {
        InitializeComponent();
        Loaded += AddOrEditDataLoaded;

    }
...
}

这是完整的堆栈跟踪:

Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.DataSource.GetPrevious(objectrelativeTo) 第 58 行 + 0x7 字节 C# Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.Balance() 第 146 行 + 0xd 字节 C# Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.UpdateData() 第 552 行 + 0xc0 字节 C# Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.LoopingSelector_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e) 第 365 行 C# System.Windows.dll!System.Windows.FrameworkElement.OnSizeChanged(对象发送者,System.Windows.SizeChangedEventArgs e)+ 0x15字节 System.Windows.dll!MS.Internal.JoltHelper.RaiseEvent(System.IntPtr target, uint eventId, System.IntPtr coreEventArgs, uint eventArgsTypeIndex) + 0xb2 字节 [本机到托管的过渡]

When I use a custome page inheriting from PhoneApplicationPage instead of directly using it, the datepicker throws a null ref exception...

My custom class:

public class CustomPhoneApplicationPage : PhoneApplicationPage
{
  public CustomPhoneApplicationPage()
  {
      Loaded += CustomPhoneApplicationPageLoaded;
      IsAnimFromDisabled = false;
      IsAnimToDisabled = false;
      this.Tap += CustomPhoneApplicationPageTap;
      InitTransition();
  }
  private void InitTransition()
  {
    RenderTransform = new CompositeTransform();
    _comeInStoryboard = Application.Current.Resources["FadeIn"] as Storyboard;
    _comeOutStoryboard = Application.Current.Resources["FadeOut"] as Storyboard;
    Debug.Assert(_comeInStoryboard != null, "_comeInStoryboard != null");
    Debug.Assert(_comeOutStoryboard != null, "_comeOutStoryboard != null");
  }
}

The use of the date picker in the Xaml:

<toolkit:DatePicker x:Name="_dateTimePicker" Value="{Binding SnapshotTime, Mode=TwoWay}" />

The exception is thrown here:

Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.DataSource.GetPrevious(object relativeTo) + 0x7 bytes

Here is how I use this class as a base for my pages in the app:

public partial class AddOrEditData : CustomPhoneApplicationPage
{


    public AddOrEditData()
    {
        InitializeComponent();
        Loaded += AddOrEditDataLoaded;

    }
...
}

Here is the full stack trace:

Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.DataSource.GetPrevious(object relativeTo) Line 58 + 0x7 bytes C#
Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.Balance() Line 146 + 0xd bytes C#
Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.UpdateData() Line 552 + 0xc0 bytes C#
Microsoft.Phone.Controls.Toolkit.dll!Microsoft.Phone.Controls.Primitives.LoopingSelector.LoopingSelector_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e) Line 365 C#
System.Windows.dll!System.Windows.FrameworkElement.OnSizeChanged(object sender, System.Windows.SizeChangedEventArgs e) + 0x15 bytes
System.Windows.dll!MS.Internal.JoltHelper.RaiseEvent(System.IntPtr target, uint eventId, System.IntPtr coreEventArgs, uint eventArgsTypeIndex) + 0xb2 bytes
[Native to Managed Transition]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2024-12-07 17:57:53

好的,

我通过将这行代码添加到我的继承页面来解决这个问题,以在离开页面时禁用一些自定义动画:

 protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
    {
        IsAnimFromDisabled = e.Uri.OriginalString == @"/Microsoft.Phone.Controls.Toolkit;component/DateTimePickers/DatePickerPage.xaml";
        base.OnNavigatingFrom(e);
    }

它有效!

谢谢大家!

Ok,

I solved it by adding this line of code to my inheriting page to disable some custom animation when leaving the page:

 protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
    {
        IsAnimFromDisabled = e.Uri.OriginalString == @"/Microsoft.Phone.Controls.Toolkit;component/DateTimePickers/DatePickerPage.xaml";
        base.OnNavigatingFrom(e);
    }

And it works !

Thanks every one !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文