首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置DataContext of CustomMessageBox

设置DataContext of CustomMessageBox
EN

Stack Overflow用户
提问于 2013-12-09 12:41:17
回答 1查看 232关注 0票数 3

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

代码语言:javascript
复制
<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>

我正试着在代码背后像这样使用它:

代码语言:javascript
复制
CustomMessageBox messageBox = new CustomMessageBox()
{
    Caption = "Title",
    DataContext = myList,
    ContentTemplate = (DataTemplate)this.LayoutRoot.Resources["CustomMessageBoxTemplate"],
    LeftButtonContent = "OK"
};
messageBox.Show();

正确设置myList的位置(我通过调试检查了它)。

但问题是,我的DataContext并没有改变,而我在CustomMessageBox中的LongListSelector没有人居住。

我不知道我在哪里出了错。我试过如何去做,但是我没有发现任何有用的东西。

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-09 15:15:11

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20470945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档