【发布时间】:2015-12-24 10:46:51
【问题描述】:
我有一个场景,我在一个窗口中有四个用户控件(如地址、技能、个人信息和一般信息,每个用户控件都有自己的控件,如文本框标签等......)每个用户控件都有自己的自己的视图模型 例如:具有人员列表和文本框年龄和文本框性别的组合框的常规信息控件 地址有 3 个文本框 Street、Area、City 具有 2 个文本框的技能控制软技能和技术技能
因此,当用户从组合框中选择特定人员时,它必须使用该特定人员数据更新所有用户控件
主窗口
<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(View)
<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>
任何人都可以帮助我以最好的方式实现这一目标 如果您对我帖子中的任何错误进行罚款,请见谅 提前致谢
【问题讨论】: