我有一個場景,我有一個窗口中的四個用戶控件(如地址,技能,個人信息和一般信息每個用戶控件都有自己的控件,如文本框標籤等....)每個用戶控件有自己的查看模型 例如:通用信息控制有一個組合框,其中有一個人名單和一個文本框年齡和文本框性別 地址有3個文本框街,區,有兩個文本框軟技能和技術技能市 控制技能如何更新同一窗口中的多個用戶控件WPF MVVM
所以當用戶從下拉框中選擇一個特定的人則有與特定人的數據更新所有的用戶控件
主窗口
<Window x:Class="CTSWpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:View="clr-namespace:CTSWpfApplication.View"
xmlns:localViewModel="clr-namespace:CTSWpfApplication.ViewModel"
Title="MainWindow" Height="600" Width="1000">
<Window.Resources>
<DataTemplate DataType="{x:Type localViewModel:PersonViewModel}">
<View:PersonVorw/>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="20*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<View:PersonVorw Grid.Row="0" Grid.Column="0" DataContext="{Binding PersonViewModel}"/>
<View:AddressView Grid.Row="0" Grid.Column="1"/>
<View:SkillsView Grid.Row="1" Grid.Column="0"/>
<View:PersonalInfoView Grid.Row="1" Grid.Column="1"/>
</Grid>
用戶控制PersonGeneralInfo(查看)
<UserControl x:Class="CTSWpfApplication.View.PersonVorw"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="500">
<Grid DataContext="{Binding PersonGenModel}">
<Grid.RowDefinitions>
<RowDefinition Height="40*"/>
<RowDefinition Height="20*"/>
<RowDefinition Height="20*"/>
<RowDefinition Height="20*"/>
<RowDefinition Height="20*"/>
<RowDefinition Height="20*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<ComboBox Height="25" Width="150" Grid.Column="1" Name="NameSelection" ItemsSource="{Binding ListFirstName}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding MySelectedItem}">
</ComboBox>
<Label Height="25" Width="100" Content="First Name" Grid.Row="1" Grid.Column="0" />
<Label Height="25" Width="100" Content="Middle Name" Grid.Row="1" Grid.Column="1"/>
<Label Height="25" Width="100" Content="Last Name" Grid.Row="1" Grid.Column="2"/>
<TextBox Height="25" Width="120" Grid.Column="0" Grid.Row="2" Name="TxTFirstName" Text="{Binding FirstName}"/>
<TextBox Height="25" Width="120" Grid.Column="1" Grid.Row="2" Name="TxTMiddleName" Text="{Binding MiddleName}"/>
<TextBox Height="25" Width="120" Grid.Column="2" Grid.Row="2" Name="TxTLastName" Text="{Binding LastName}"/>
<Label Height="25" Width="100" Content="Age" Grid.Row="3" Grid.Column="0"/>
<Label Height="25" Width="100" Content="Gender" Grid.Row="4" Grid.Column="0"/>
<TextBox Height="25" Width="120" Grid.Column="1" Grid.Row="3" Name="TxTAge" Text="{Binding Age}"/>
<TextBox Height="25" Width="120" Grid.Column="1" Grid.Row="4" Name="TxTGender" Text="{Binding Gender}"/>
<Button Name="BtNPerson" Height="25" Width="100" Content="Clenter code hereick to Add" Grid.Row="5" Grid.Column="2" />
</Grid>
任何一個可以幫助我在以最好的方式來實現這一目標 請原諒我如果你在我的帖子中有任何錯誤 在此先感謝