首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ContentControl VisualStateManager

ContentControl VisualStateManager
EN

Stack Overflow用户
提问于 2013-04-17 16:38:47
回答 1查看 540关注 0票数 0

我有一个ContentControl,它将内容绑定到一个变量

代码语言:javascript
复制
    <ContentControl x:Name="MyContentControl" Content="{Binding MyContent}" />

ContentControl在我的视图'MainPage.xaml‘中当我点击一个按钮时,我的ContentControl的内容被设置为一个新的视图,即'FirstPage.xaml‘。所以我有MainPage.xaml,它包含一个内容为'FirstPage.xaml‘的ContentControl。

问题是我在我的MainPage.xaml和FirstPage.xaml中设置了一个VisualStateManager。

如果我在Xaml-Editor中测试这两个VisualState的“Snapped”,它工作得很好。Problem -> MainPage.xaml包含ContentControl = FirstPage.xaml。如果对MainPage.xaml进行了快照,则只会应用MainPage的VisualState,但ContentControl仍然是相同的(不会在ContentControl中更改VisualState )。

那么如何在ContentControl中应用VisualState呢?

EN

回答 1

Stack Overflow用户

发布于 2013-04-19 15:24:05

问题解决了。我必须将这段代码放到代码隐藏中:

代码语言:javascript
复制
    public MainPage()
    {
        this.InitializeComponent();
        Window.Current.SizeChanged += Current_SizeChanged;  
    }

    void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        VisualStateManager.GoToState(this, ApplicationView.Value.ToString(), true);
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16055384

复制
相关文章

相似问题

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