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]
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 !