基于视图模型属性更新的 Silverlight 行为
我希望有一个 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}" />
这一切都工作正常。现在,我想将一个行为附加到 myTextBlock
,该行为是由视图模型中 ChangingProperty
的更改触发的。例如,该行为应突出显示 TextBlock
(或更复杂的内容)。
如何指定这个触发器?这有可能吗?
亲切的问候,
罗纳德
I'd like to have a Silverlight behavior that is triggered by a change to a property in the view model for my page. I can't figure out how to do this, however.
So, I have a very simple view model:
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.......
}
This view model is the data context for a user control that has a text block bound to SomeProperty
:
<TextBlock x:Key="myTextBlock" Text="{Binding SomeProperty}" />
This all works fine. Now I'd like to attach a behavior to myTextBlock
that is triggered by changes to ChangingProperty
in my view model. The behavior should highlight the TextBlock
, for example (or something more sophisticated).
How do I specify this trigger? Is this possible at all?
Kind regards,
Ronald
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对类似问题的回答此处可能会有所帮助。
以下是如何将该技术应用于您的需求的示例。
Something along the lines of my answer to a similar issue here might help.
Here is an example of how you might apply that technique to your requirement.