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.
38 lines
1.8 KiB
38 lines
1.8 KiB
<Window x:Class="ex_DataTemplateSelector.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:ex_DataTemplateSelector"
|
|
mc:Ignorable="d"
|
|
Title="MainWindow" Height="800" Width="800">
|
|
<Window.Resources>
|
|
<local:Formes x:Key="formes"/>
|
|
<DataTemplate x:Key="circleTemplate">
|
|
<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" Fill="Red"/>
|
|
</DataTemplate>
|
|
<DataTemplate x:Key="rectangleTemplate">
|
|
<Rectangle Width="{Binding Width}" Height="{Binding Height}" Fill="Green"/>
|
|
</DataTemplate>
|
|
<local:FormeTemplateSelector CircleTemplate="{StaticResource circleTemplate}"
|
|
RectangleTemplate="{StaticResource rectangleTemplate}"
|
|
x:Key="formeTemplateSelector"/>
|
|
</Window.Resources>
|
|
<Grid>
|
|
<ItemsControl ItemTemplateSelector="{StaticResource formeTemplateSelector}"
|
|
ItemsSource="{StaticResource formes}">
|
|
<ItemsControl.ItemsPanel>
|
|
<ItemsPanelTemplate>
|
|
<Canvas Background="LightSalmon"/>
|
|
</ItemsPanelTemplate>
|
|
</ItemsControl.ItemsPanel>
|
|
<ItemsControl.ItemContainerStyle>
|
|
<Style>
|
|
<Setter Property="Canvas.Top" Value="{Binding Y}" />
|
|
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
|
</Style>
|
|
</ItemsControl.ItemContainerStyle>
|
|
</ItemsControl>
|
|
</Grid>
|
|
</Window>
|