【问题标题】:Change VisualState of a VisualElement with Prism, in Xamarin.Forms在 Xamarin.Forms 中使用 Prism 更改 VisualElement 的 VisualState
【发布时间】:2019-01-15 16:07:24
【问题描述】:

如何从 Prism ViewModel 更改元素的 VisualState? 有我可以使用的 Bindable 属性吗?

谢谢!

【问题讨论】:

    标签: mvvm xamarin.forms prism visualstatemanager


    【解决方案1】:

    为了改变元素的视觉状态,您可以从页面的代码隐藏中进行,如下所示:

    VisualStateManager.GoToState(yourViewElement, yourViewElementState);
    

    但是,这不是最好的建议,但您可以从 code.behind 订阅视图模型中的更改,然后调用 VisualStateManager。

    例子

    YourPage()
    {
        viewModel.PropertyChanged += FooChanged;
    }
    
    public void FooChanged()
    {
         if (!args.PropertyName.Equals("YourProperty"))
         {
              VisualStateManager.GoToState(yourViewElement, yourViewElementState);
         }
            return;
    }
    

    【讨论】:

    • 谢谢,但我正在寻找一种在 ViewModel 中执行此操作而无需触及页面代码隐藏的方法
    【解决方案2】:

    在这篇文章中找到了解决方案,在 XAML 页面中添加了一个 Behavior: https://forums.xamarin.com/discussion/127531/behavior-bindableproperty-not-update

    【讨论】:

      猜你喜欢
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 2021-07-01
      相关资源
      最近更新 更多