90 lines
5.0 KiB
XML
90 lines
5.0 KiB
XML
<UserControl x:Class="Life.AutomatonField"
|
|
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:local="clr-namespace:Life"
|
|
mc:Ignorable="d"
|
|
d:DesignHeight="300" d:DesignWidth="300">
|
|
<UserControl.Resources>
|
|
<ResourceDictionary>
|
|
<Style TargetType="Button" x:Key="Cell">
|
|
<Style.Triggers>
|
|
<DataTrigger Binding="{Binding IsAlive}" Value="True">
|
|
<DataTrigger.EnterActions>
|
|
<BeginStoryboard>
|
|
<Storyboard>
|
|
<ColorAnimation Duration="0:0:0.15" To="Black" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)"/>
|
|
</Storyboard>
|
|
</BeginStoryboard>
|
|
</DataTrigger.EnterActions>
|
|
<DataTrigger.ExitActions>
|
|
<BeginStoryboard>
|
|
<Storyboard>
|
|
<ColorAnimation Duration="0:0:0.15" From="Black" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)"/>
|
|
</Storyboard>
|
|
</BeginStoryboard>
|
|
</DataTrigger.ExitActions>
|
|
</DataTrigger>
|
|
<EventTrigger RoutedEvent="MouseEnter">
|
|
<BeginStoryboard>
|
|
<Storyboard>
|
|
<ColorAnimation Duration="0:0:0.05" To="Aqua" Storyboard.TargetProperty="(Button.BorderBrush).(SolidColorBrush.Color)"/>
|
|
</Storyboard>
|
|
</BeginStoryboard>
|
|
</EventTrigger>
|
|
<EventTrigger RoutedEvent="MouseLeave">
|
|
<BeginStoryboard>
|
|
<Storyboard>
|
|
<ColorAnimation Duration="0:0:0.05" From="Aqua" Storyboard.TargetProperty="(Button.BorderBrush).(SolidColorBrush.Color)"/>
|
|
</Storyboard>
|
|
</BeginStoryboard>
|
|
</EventTrigger>
|
|
</Style.Triggers>
|
|
|
|
<Setter Property="Background" Value="LightGray"/>
|
|
<Setter Property="Template">
|
|
<Setter.Value>
|
|
<ControlTemplate TargetType="Button">
|
|
<Border x:Name="Border"
|
|
BorderThickness="{TemplateBinding BorderThickness}"
|
|
Background="{TemplateBinding Background}"
|
|
BorderBrush="{TemplateBinding BorderBrush}">
|
|
<ContentPresenter Margin="2"
|
|
HorizontalAlignment="Center"
|
|
VerticalAlignment="Center"
|
|
RecognizesAccessKey="True"/>
|
|
</Border>
|
|
</ControlTemplate>
|
|
</Setter.Value>
|
|
</Setter>
|
|
</Style>
|
|
</ResourceDictionary>
|
|
</UserControl.Resources>
|
|
<Border Background="LightGray" BorderThickness="{Binding Separation}"
|
|
BorderBrush="LightGray" DataContext="{Binding ViewModel, RelativeSource={RelativeSource AncestorType={x:Type local:AutomatonField}}}">
|
|
<ItemsControl ItemsSource="{Binding Cells}">
|
|
<ItemsControl.ItemsPanel>
|
|
<ItemsPanelTemplate>
|
|
<Canvas Width="{Binding Width}" Height="{Binding Height}" />
|
|
</ItemsPanelTemplate>
|
|
</ItemsControl.ItemsPanel>
|
|
<ItemsControl.ItemTemplate>
|
|
<DataTemplate>
|
|
<Button Width="{Binding Size, RelativeSource={RelativeSource AncestorType={x:Type local:AutomatonField}}}"
|
|
Height="{Binding Size, RelativeSource={RelativeSource AncestorType={x:Type local:AutomatonField}}}"
|
|
Style="{DynamicResource Cell}"
|
|
Command="{Binding ClickCommand, RelativeSource={RelativeSource AncestorType={x:Type local:AutomatonField}}}"
|
|
CommandParameter="{Binding Position}"
|
|
/>
|
|
</DataTemplate>
|
|
</ItemsControl.ItemTemplate>
|
|
<ItemsControl.ItemContainerStyle>
|
|
<Style>
|
|
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
|
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
|
</Style>
|
|
</ItemsControl.ItemContainerStyle>
|
|
</ItemsControl>
|
|
</Border>
|
|
</UserControl> |