You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

2 years ago
<Window x:Class="MVVMComboBoxSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MVVMComboBoxSample"
xmlns:vm ="clr-namespace:MVVMComboBoxSample.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="500">
<Window.Resources>
<vm:StudentViewModel x:Key="vm"/>
</Window.Resources>
<StackPanel DataContext="{Binding Source={StaticResource vm}}">
<ComboBox HorizontalAlignment="Center"
Margin="10"
VerticalAlignment="Top"
Width="300"
ItemsSource="{Binding Students}"
SelectedItem="{Binding SelectedStudent}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ID}"/>
<TextBlock Text="-"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="-"/>
<TextBlock Text="{Binding Age}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</Window>