コードビハインドでTabItemヘッダークリックイベントの処理に関する多くの回答を見つけましたが、ビューモデルでそのイベントを処理する必要があります。前もって感謝します
4170 次
2 に答える
2
プロパティをタブコントロールSelectedIndexにバインドします。
XAML:
<TabControl x:Name="tabControl" SelectedIndex="{Binding tabControlSelectedIndex}">
あなたのViewModel:
Private _tabControlSelectedIndex As Integer
Public Property tabControlSelectedIndex As Integer
Get
Return _tabControlSelectedIndex
End Get
Set(value As Integer)
If _tabControlSelectedIndex <> value Then
_tabControlSelectedIndex = value
OnPropertyChanged("tabControlSelectedIndex")
'
' Whatever you want to handle here
'
End If
End Set
End Property
于 2013-02-16T11:35:00.373 に答える
1
MVVMライトのEventToCommand
アプローチを使用できます。
プロジェクトへの参照を追加
System.Windows.Interactivity.dll
します。追加
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xamlを追加します。例:
<Button> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseEnter" > <i:InvokeCommandAction Command="{Binding FooCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </Button>
ここでコードを見ることができます: http ://www.danharman.net/2011/08/05/binding-wpf-events-to-mvvm-viewmodel-commands/
于 2013-02-16T11:40:13.367 に答える