私はあなたの質問があまりにも漠然としているので、あなたはその作品を一緒に引っ張る方法がかなりわからないので、ここから推測しています。わかりやすくするために、ViewModelをユーザーコントロールに直接フックして、すべてのバインディングを取得してみましょう。
ビューモデルに正しい人物が設定されている限り、下のすべてのバインディングがデータを処理して正しいデータを表示します。コンボボックスで選択された項目の双方向バインディングに注意してください。これにより、WPFは新しい選択項目をビューモデルに返送することができます。 UserControlのXAMLで
public MyUserControl()
{
DataContext = new MyViewModel();
}
:背後にあるUserControlのコードで
<ComboBox ItemsSource="{Binding AllPeople}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
<TextBox Text="{Binding SelectedItem.LastName}" />
<TextBox Text="{Binding SelectedItem.FirstName}" />
<TextBox Text="{Binding SelectedItem.EmailName}" />
あなたのViewModel:私はあなたの質問はもう少し明確にする必要があると思う
private IEnumerable<Person> _allPeople;
public IEnumerable<Person> AllPeople
{
get { return _allPeople; }
set
{
if (_allPeople != value)
{
_allPeople = value;
NotifyPropertyChanged("AllPeople");
}
}
}
private Person _selectedItem;
public Person SelectedItem
{
get { return _selectedItem; }
set
{
if (!_selectedItem != value)
{
_selectedItem = value;
NotifyPropertyChanged("SelectedItem");
}
}
}
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName);
}
}
}
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
、あなたあなたはMVVMを使用していると言いました。あなたのサンプルで直面している限界は何ですか? –