我有一个MVVM应用程序,我想跟踪ViewModel中的焦点元素。
我想在聚焦TextBox时设置ViewModel属性。
我想要这样的东西
<TextBox Text="{Binding P1}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="{Binding P1Selected}" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
其中P1和P1Selected是viewModel属性。
当然,此代码不起作用。我写它只是为了给出想法。
最佳答案
抱歉,我的回答是错误的。
请参阅OneWayToSource binding from readonly property in XAML。
关于wpf - 聚焦TextBox时设置ViewModel属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9905896/