wpf - 聚焦TextBox时设置ViewModel属性

标签 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属性。
当然,此代码不起作用。我写它只是为了给出想法。

最佳答案

抱歉,我的回答是错误的。
请参阅OneWayToSource binding from readonly property in XAML

关于wpf - 聚焦TextBox时设置ViewModel属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9905896/

相关文章:

python - PySide 的 MVVM 模式

c# - 获取所有打开的 WPF 窗口

c# - 当我们使用双流时,GUI会卡住

mvvm - RadGridView 编辑按钮命令在 Prism 4.1 Silverlight 5 中未绑定(bind)

c# - 从其他ViewModel调用方法

java - jTextFields 请求焦点(如果在丢失焦点后为空)不起作用

javascript - 如何使用javascript写入在后台打开的新选项卡

java - 将焦点放在 JLayeredPane 中的 JPanel

WPF 按钮相同/推荐宽度

wpf - ListView 列自动调整大小