当我的页面继承自 PhoneApplicationPage 时,WP7 Silverlight 工具包日期选择器引发空引用异常
当我使用从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,
我通过将这行代码添加到我的继承页面来解决这个问题,以在离开页面时禁用一些自定义动画:
它有效!
谢谢大家!
Ok,
I solved it by adding this line of code to my inheriting page to disable some custom animation when leaving the page:
And it works !
Thanks every one !