Window1.xaml
<Window
x:Class="MedicalRecord.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:Extend="clr-namespace:MedicalRecord"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MedicalRecord"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Window1"
Width="800"
Height="450"
mc:Ignorable="d"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Extend:Form Width="500" HorizontalAlignment="Left">
<Expander
Extend:Form.IsItemItsOwnContainer="True"
Header="用户信息"
IsExpanded="True">
<Extend:Form Padding="0" Grid.IsSharedSizeScope="False">
<TextBox
Extend:Form.IsRequired="True"
Extend:Form.Label="用户名"
Text="{Binding Name, Mode=TwoWay}" />
<PasswordBox Extend:Form.IsRequired="True" Extend:Form.Label="密码" />
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},
Path=DataContext.WifeList}" x:Name="_Printer"
DisplayMemberPath="ChName" SelectedValuePath="EnName"
SelectedValue="{Binding Wife, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding selectItemChangedCommand}"
CommandParameter="{Binding ElementName=_Printer,Path=SelectedIndex}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</Extend:Form>
</Expander>
</Extend:Form>
</Window>
Window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace MedicalRecord
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
}
Window1ViewModel.cs
using MedicalRecord.ComponentModule.ViewModels;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace MedicalRecord
{
public class Window1ViewModel
{
private DelegateCommand<object> _selectItemChangedCommand;
public DelegateCommand<object> selectItemChangedCommand =>
_selectItemChangedCommand ?? (_selectItemChangedCommand = new DelegateCommand<object>(BindViewModelObject));
async void BindViewModelObject(object obj)
{
if (obj != null)
{
MessageBox.Show(obj.ToString());
//objectMap(obj as MedicalRecordCatalogue);
}
}
public ObservableCollection<Person> PersonList =>
new ObservableCollection<Person>
{
new Person{UserName="孙悟空",UserId="1"},
new Person{UserName="猪八戒",UserId="2"},
new Person{UserName="沙和尚",UserId="3"},
new Person{UserName="唐僧",UserId="4"},
};
public ObservableCollection<WifeInfo> WifeList =>
new ObservableCollection<WifeInfo>
{
new WifeInfo{ChName="铁扇公主",EnName="Mary"},
new WifeInfo{ChName="观音菩萨",EnName="Lily"},
new WifeInfo{ChName="女儿国国王",EnName="Lisa"},
new WifeInfo{ChName="兔子精",EnName="White"},
};
}
}