Silverlight DataStateBehavior,未使用初始值 [英] Silverlight DataStateBehavior, initial value not used

查看:85
本文介绍了Silverlight DataStateBehavior,未使用初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Silverlight DataStateBehavior,在大多数情况下,当我单击将视图模型中的"Selected"属性设置为false或true的按钮时,它可以正常工作.然后,DataStateBehavior告诉VisualStateManager进入相关状态.

I am trying to use the Silverlight DataStateBehavior, it works fine in most cases where I click a button which sets say a 'Selected' Property in the view model to either false or true. The DataStateBehavior then tells the VisualStateManager to go to the relevant state.

赞:

   <Button...>
   <i:Interaction.Behaviors>
             <id:DataStateBehavior Binding="{Binding Selected}" Value="True" TrueState="SelectedVisualState" FalseState="DeselectedVisualState"/>
          </i:Interaction.Behaviors>
   </Button>

以上工作正常.我要尝试做的是让它在应用程序加载时设置正确的状态,如果我默认将视图模型上的"Selected"属性设置为true,则直到在UI上都看不到任何更改我单击按钮以更改viewmodel属性.

The above works fine. What I am trying to do though is to get it to set the correct state when the application loads, if I were to set the 'Selected' property on the view model to true by default I wouldn't see any changes in the UI until I clicked the button to change the viewmodel property.

我知道DataState涉及几个类,包括:

I know there are several classes involved with the DataState stuff including:

  • BindingListener.cs
  • ConverterHelper.cs
  • DataStateBehavior.cs
  • DataStateSwitchBehavior.cs
  • DataTrigger.cs

任何线索都会很好, 谢谢

Any clues would be good, Thanks

推荐答案

我实际上将添加我刚刚尝试过的第二个答案,并且看起来更干净,因为它可以在XAML中完成并且无需自定义行为.我将把其他答案作为替代解决方案的参考,因为它们都可以使用.

I'm actually going to add a second answer which I just tried, and seems to be cleaner since it can be done all in XAML and without a custom behavior. I'll leave the other answer just as a reference for an alternative solution since they both work.

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <ic:GoToStateAction StateName="SelectedVisualState"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

您只需要添加对Blend.sdk一部分的Microsoft.Expression.Interactions程序集的引用即可.

You will just need at add a reference to the Microsoft.Expression.Interactions assembly that is part of the Blend SDK.

xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"

这篇关于Silverlight DataStateBehavior,未使用初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆