Question

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!

Was it helpful?

Solution

The DataContext of the xaml inside the ContentTemplate automatically gets set to the Content property. Try setting Content = myList

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top