我正在使用MVVM/WPF并试图做一些看似简单的事情,但无法找到干净的解决方案。在同一时间访问DataContext和代码中的属性
我要做到以下几点:
当模型中的一个属性更改(WPF文本框的文本会在这种情况下进行更改),使用方法上与绑定的属性的UI执行其他操作。
当前我在工具提示上使用多重绑定(获取文本框datacontext +绑定路径),但这有点破解。
<TextBox x:Name="textBox" Text="{Binding Model.MyProperty}">
<TextBox.ToolTip>
<MultiBinding Converter="{StaticResource brNewMultiConverter}">
<!-- This to trigger the converter in all required cases.
Without it, i cant get the event to fire when filling
the model initially
-->
<Binding ElementName="textBox" Path="Text" />
<!-- This has the properties i need, but wont fire without
the binding above -->
<Binding ElementName="textBox" />
</MultiBinding>
</TextBox.ToolTip>
</TextBox>
我想提出一些可重复使用的,并可能是针对不同的控制,所以我不是只用TextChanged事件。
如果任何人都可以指出我正确的方向,它将不胜感激。
“使用方法上与绑定的属性的UI执行其他操作。”如果这是特定的,就有可能为实现这一目的的方式提供建议。 – Will