<Window x:Class="KoloryWPF.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:KoloryWPF"
        xmlns:vm="clr-namespace:KoloryWPF.ModelWidoku"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" 
        KeyDown="Window_KeyDown" >
        <!--
        Closed="Window_Closed">
        -->
    <Window.Resources>
        <local:ByteToDoubleConverter x:Key="byte2double" />
        <local:RGBToColorConverter x:Key="rgb2color" Reverse="False" />
        <local:ToStringConverter x:Key="toString" />
    </Window.Resources>
    <Window.DataContext>
        <vm:EdycjaKoloru />
    </Window.DataContext>
    <Window.InputBindings>
        <KeyBinding Key="R" Modifiers="Ctrl" Command="{Binding Resetuj}" />
        <MouseBinding Gesture="Alt+MiddleClick" Command="{Binding Resetuj}" />
    </Window.InputBindings>
    <!-- NuGet: Expression.Blend.Sdk.WPF -->
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding Zapisz}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Rectangle x:Name="rectangle" 
                   Margin="10,10,10,94" Stroke="Black">
            <Rectangle.Fill>
                <!--
                <SolidColorBrush Color="{Binding Color, Mode=OneWay}" />
                -->
                <SolidColorBrush>
                    <SolidColorBrush.Color>
                        <MultiBinding Converter="{StaticResource rgb2color}">
                            <Binding Path="R" />
                            <Binding Path="G" />
                            <Binding Path="B" />
                        </MultiBinding>
                    </SolidColorBrush.Color>
                </SolidColorBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Slider x:Name="sliderR" Value="{Binding R, Mode=TwoWay, Converter={StaticResource byte2double}}"
                Margin="10,0,66,64" Height="22" 
                VerticalAlignment="Bottom" Maximum="255" />
        <Slider x:Name="sliderG" Value="{Binding G, Mode=TwoWay, Converter={StaticResource byte2double}}"
                Margin="10,0,66,37" Height="22" 
                VerticalAlignment="Bottom" Maximum="255" />
        <Slider x:Name="sliderB" Value="{Binding B, Mode=TwoWay, Converter={StaticResource byte2double}}"
                Margin="10,0,66,10" Height="22" 
                VerticalAlignment="Bottom" Maximum="255" />
        <!-- Świadomie nie używam StringFormat -->
        <!-- Działa też bez konwertera -->
        <TextBlock Text="{Binding ElementName=sliderR, Path=Value, Mode=OneWay, Converter={StaticResource toString}}" Margin="0,0,10,64" Height="26" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="38"/>
        <TextBlock Text="{Binding ElementName=sliderG, Path=Value, Mode=OneWay, Converter={StaticResource toString}}" Margin="0,0,10,38" RenderTransformOrigin="0.414,0.596" Height="26" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="38"/>
        <TextBlock Text="{Binding ElementName=sliderB, Path=Value, Mode=OneWay, Converter={StaticResource toString}}" Margin="0,0,10,10" Height="26" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="38"/>
        <Button Content="Reset" HorizontalAlignment="Left" Margin="43,44,0,0" VerticalAlignment="Top" Width="75" 
                Command="{Binding Resetuj}"/>
    </Grid>
</Window>
