<Window x:Class="KolekcjeWPF.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:KolekcjeWPF"        
        xmlns:mw="clr-namespace:KolekcjeWPF.ModelWidoku"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="Kolekcje WPF" Height="500" Width="500">
    <Window.DataContext>
        <mw:Zadania />
    </Window.DataContext>
    <Window.Resources>
        <Style x:Key="stylPrzycisku" TargetType="Button">
            <Setter Property="FontSize" Value="10" />
            <Setter Property="Margin" Value="5" />
            <Setter Property="Width" Value="85" />
            <Setter Property="Height" Value="20" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Top" />
        </Style>
        <BooleanToVisibilityConverter x:Key="b2v" />
        <local:ZadanieConverter x:Key="konwerterZadania" />
    </Window.Resources>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding Zapisz}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <TextBlock Margin="10,13,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Liczba zadań: ">
            <Run Text="{Binding Path=ListaZadań.Count, Mode=OneWay}" />
        </TextBlock>
        <ListBox x:Name="lbListaZadań" Margin="10,35,10,200"
            ItemsSource="{Binding Path=ListaZadań}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Margin="3">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=Opis, Mode=OneWay}" FontSize="20" />
                            <Button Content="Zrealizowane" Command="{Binding Path=OznaczJakoZrealizowane}" Style="{StaticResource stylPrzycisku}"
                                    Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, 
                                                         Mode=OneWay, Converter={StaticResource b2v}}" />
                            <Button Content="Niezrealizowane" Command="{Binding Path=OznaczJakoNiezrealizowane}" Style="{StaticResource stylPrzycisku}" 
                                    Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, 
                                                         Mode=OneWay, Converter={StaticResource b2v}}" />
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Margin" Value="3" />
                    <Setter Property="BorderBrush" Value="Black" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="LightGray" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
        <Button Content="Usuń zaznaczone zadanie"
                VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10,0,0,165" Width="150" Height="25"
                Style="{StaticResource stylPrzycisku}"
                Command="{Binding Path=UsuńZadanie}"
                CommandParameter="{Binding ElementName=lbListaZadań, Path=SelectedIndex}" />
        <GroupBox Header="Nowe zadanie" Margin="10,0,10,10" MinWidth="420" Height="140" VerticalAlignment="Bottom">
            <Grid>
                <Label Content="Opis:" Margin="10,5,0,0"
                       HorizontalAlignment="Left" VerticalAlignment="Top" />
                <TextBox x:Name="tbOpis" Height="23" Margin="10,30,10,0"
                       VerticalAlignment="Top" />
                <Label Content="Priorytet:" Margin="10,60,0,0"
                       HorizontalAlignment="Left" VerticalAlignment="Top" />
                <ComboBox x:Name="cbPriorytet" Margin="10,85,0,0" Width="120"
                          HorizontalAlignment="Left" VerticalAlignment="Top">
                    <ComboBoxItem>MniejWażne</ComboBoxItem>
                    <ComboBoxItem>Standardowe</ComboBoxItem>
                    <ComboBoxItem>Ważne</ComboBoxItem>
                    <ComboBoxItem> Krytyczne</ComboBoxItem>
                </ComboBox>
                <Label Content="Data realizacji:" Margin="160,60,0,0"
                       HorizontalAlignment="Left" VerticalAlignment="Top" />
                <DatePicker x:Name="dpDataRealizacji" Margin="160,85,0,0"
                            HorizontalAlignment="Left" VerticalAlignment="Top"
                            SelectedDate="{x:Static s:DateTime.Now}" />
                <Button Content="DodajZadanie" Margin="0,85,10,0"
                        Height="23" Width="130" HorizontalAlignment="Right" VerticalAlignment="Top"
                        Command="{Binding DodajZadanie}">
                    <Button.CommandParameter>
                        <MultiBinding Converter="{StaticResource konwerterZadania}">
                            <Binding ElementName="tbOpis" Path="Text" />
                            <Binding ElementName="dpDataRealizacji" Path="SelectedDate" />
                            <Binding ElementName="cbPriorytet" Path="SelectedIndex" />
                        </MultiBinding>
                    </Button.CommandParameter>
                </Button>
            </Grid>
        </GroupBox>
    </Grid>
</Window>
