私のWPF MVVMプロジェクトでは、XMLにノードを追加し、フォーカスをテキストボックスに設定する関数をトリガーするボタンがあります。 私の質問は、どのようにコントロールへの参照を受け取ることができますか?WPF(MVVM)でコントロールへの参照を受け取る方法はありますか?
ビュー:
<Button Command="{Binding Path=ButtonAddCategory_Click}" />
のViewModel:
RelayCommand buttonAddCategory_Click;
public ICommand ButtonAddCategory_Click
{
get
{
return buttonAddCategory_Click ?? (buttonAddCategory_Click = new RelayCommand(param => this.AddCategory(),
param => true));
}
}
public void AddCategory()
{
...
//get the "node" -> reference?
XmlNode selectedItem = (XmlNode)treeView.SelectedItem;
..
//add the node to the xml
..
//change focus -> reference?
textBoxTitel.Focus();
textBoxTitel.SelectAll();
}
TreeViewsは残念ながらMVVMでうまくいきません... – Will
実際にはMVVMでうまくプレイできますが、少し作業が必要です... SelectedItemをバインドします。参照してください[この記事](http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx)Josh Smith –
@ ThomasLevesque:lurl、私は他のコントロールと同じ能力を得るために少しの作業を行います箱から出てきても、いい演奏として私を叩くことはありません。 – Will