2012-03-28 133 views
1

我有一個MVVM應用程序,我想跟蹤ViewModel中的焦點元素。當TextBox集中時設置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是視圖模型屬性。 當然這個代碼不起作用。我寫它只是爲了給出這個想法..

回答

-5

對不起,我的回答是錯誤的。 請參閱OneWayToSource binding from readonly property in XAML

+3

您無法綁定IsFocused。因爲它是隻讀屬性。 – Amit 2012-03-28 11:46:44

+0

更正綁定模式到OneWayToSource – LPL 2012-03-28 11:53:08

+2

你仍然不能這樣做。請參閱http://stackoverflow.com/questions/658170/onewaytosource-binding-from-readonly-property-in-xaml – Amit 2012-03-28 11:57:46

相關問題