在聚焦TextBox时设置ViewModel属性

时间:2012-03-28 10:46:46

标签: wpf mvvm focus

我有一个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属性。 当然这段代码不起作用。我写这篇文章只是为了给出这个想法..

1 个答案:

答案 0 :(得分:-5)

对不起,我的答案错了。 请参阅OneWayToSource binding from readonly property in XAML