ビューモデルプロパティの更新に基づくSilverlightの動作
-
05-07-2019 - |
質問
ページのビューモデルのプロパティの変更によってトリガーされるSilverlightの動作が必要です。ただし、これを行う方法がわかりません。
つまり、非常にシンプルなビューモデルがあります:
public class MyViewModel : INotifyPropertyChanged
{
private bool changingProperty;
public bool ChangingProperty
{
get { return changingProperty; }
set
{
if (changingProperty != value)
{
changingProperty = value;
NotifyPropertyChanged("ChangingProperty");
}
}
}
public string SomeProperty { get { return "SomePropertyValue"; } }
// INotifyPropertyChanged implementation here.......
}
このビューモデルは、 SomeProperty
にバインドされたテキストブロックを持つユーザーコントロールのデータコンテキストです。
<TextBlock x:Key="myTextBlock" Text="{Binding SomeProperty}" />
これはすべて正常に動作します。次に、ビューモデルの ChangingProperty
の変更によってトリガーされる myTextBlock
にビヘイビアをアタッチしたいと思います。この動作は、たとえば TextBlock
を強調表示する必要があります(またはより洗練されたもの)。
このトリガーを指定するにはどうすればよいですか?これはまったく可能ですか?
よろしく、
ロナルド
解決
同様の問題に対する私の答えに沿った何かこちらヘルプ。
このテクニックを要件に適用する方法の例を次に示します。
<Grid.Resources>
<local:BoolToBrushConverter x:Key="Highlighter"
FalseBrush="Transparent" TrueBrush="Yellow" />
</Grid.Resources>
<Border Background="{Binding ChangingProperty, Converter={StaticResource Highlighter}}">
<TextBlock x:Name="txtTarget" Text="{Binding SomeProperty}" />
</Border>
所属していません StackOverflow