comboboxパターンを使用して、Observable コレクションを にMVVMバインドしています。正常にバインドできますcomboboxが、現在、ビュー モデルでプロパティを取得する方法を探していSelectedItemます (パターンにブレーキがかかるため、単純に呼び出すことはできません)。私がそれを描く方法はXAML、選択したアイテムを指し、後でビューモデルで使用できるバインディングを作成する方法がなければならないということです。
これを達成する方法について何か提案はありますか?
XAML
<ComboBox SelectedIndex="0" DisplayMemberPath="Text" ItemsSource="{Binding Path=DocumentTypeCmb,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Grid.Column="1" Grid.Row="4" Margin="0,4,5,5" Height="23"
HorizontalAlignment="Left" Name="cmbDocumentType" VerticalAlignment="Bottom"
Width="230" />
コード
//Obesrvable collection property
private ObservableCollection<ListHelper> documentTypeCollection = new ObservableCollection<ListHelper>();
public ObservableCollection<ListHelper> DocumentTypeCmb
{
get
{
return documentTypeCollection;
}
set
{
documentTypeCollection = value;
OnPropertyChanged("DocumentTypeCmb");
}
}
//Extract from the method where i do the binding
documentTypeCollection.Add(new ListHelper { Text = "Item1", IsChecked = false });
documentTypeCollection.Add(new ListHelper { Text = "Item2", IsChecked = false });
documentTypeCollection.Add(new ListHelper { Text = "Item3", IsChecked = false });
DocumentTypeCmb = documentTypeCollection;
//Helper class
public class ListHelper
{
public string Text { get; set; }
public bool IsChecked { get; set; }
}