gpt4 book ai didi

xaml - 设置 CustomMessageBox 的 DataContext

转载 作者:行者123 更新时间:2023-12-05 07:59:52 26 4
gpt4 key购买 nike

我需要在 xaml 中设置 CustomMessageBox 的 DataTemplate,如下所示:

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

我正在尝试像这样在我的代码隐藏中使用它:

CustomMessageBox messageBox = new CustomMessageBox()
{
Caption = "Title",
DataContext = myList,
ContentTemplate = (DataTemplate)this.LayoutRoot.Resources["CustomMessageBoxTemplate"],
LeftButtonContent = "OK"
};
messageBox.Show();

其中myList是正确设置的List(我通过调试检查过的)。

但问题是我的 DataContext 没有改变,我在 CustomMessageBox 中的 LongListSelector 仍然没有填充。

我不知道我哪里弄错了。我尝试搜索如何执行此操作,但没有找到任何有用的信息。

感谢您的帮助!

最佳答案

ContentTemplate 中 xaml 的 DataContext 自动设置为 Content 属性。尝试设置 Content = myList

关于xaml - 设置 CustomMessageBox 的 DataContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20470945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com