I need to have my DataTemplate of CustomMessageBox set in xaml like here:
<Grid.Resources>
<DataTemplate x:Key="CustomMessageBoxTemplate">
<phone:LongListSelector
LayoutMode="Grid"
ItemsSource="{Binding}"
GridCellSize="210 200"
toolkit:TiltEffect.IsTiltEnabled="True"
ItemTemplate="{StaticResource ItemTemplate}" />
</DataTemplate>
</Grid.Resources>
And I'm trying to use it in my code-behind like this:
CustomMessageBox messageBox = new CustomMessageBox()
{
Caption = "Title",
DataContext = myList,
ContentTemplate = (DataTemplate)this.LayoutRoot.Resources["CustomMessageBoxTemplate"],
LeftButtonContent = "OK"
};
messageBox.Show();
Where myList is correctly set List (I checked it by debugging).
But the problem is that my DataContext isn't changing and my LongListSelector in CustomMessageBox stays unpopulated.
I don't know where I make a mistake. I have tried to search how to do it but I haven't found anything helpful.
Thanks for any help!
The
DataContext
of the xaml inside theContentTemplate
automatically gets set to theContent
property. Try settingContent = myList