WP7 Silverlight toolkit date picker throws a null ref exception when my page inherits from PhoneApplicationPage
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.Re开发者_JS百科sources["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]
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 !
精彩评论