<UserControl x:Class="GeekDesk.Control.UserControls.Backlog.TodoControl"
             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:GeekDesk.Control.UserControls.PannelCard"
             xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:ToDoInfo}"
             mc:Ignorable="d" 
             Background="Transparent"
             >

    <UserControl.Resources>
        <!--<cst:Count2VisibleConvert x:Key="Count2VisibleConvert"/>
        <cst:CountGreZero2BoolConvert x:Key="CountGreZero2BoolConvert"/>
        <Style x:Key="NoDataStyle" TargetType="TextBlock">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=BacklogList, Path=Items.Count, Converter={StaticResource CountGreZero2BoolConvert}}" Value="False">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=BacklogList, Path=Items.Count, Converter={StaticResource CountGreZero2BoolConvert}}" Value="True">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ToDoStyle" TargetType="DataGrid">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=BacklogList, Path=Items.Count, Converter={StaticResource CountGreZero2BoolConvert}}" Value="True">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=BacklogList, Path=Items.Count, Converter={StaticResource CountGreZero2BoolConvert}}" Value="False">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>-->
    </UserControl.Resources>
    <hc:SimplePanel Margin="20" Background="Transparent">
        <Grid Background="Transparent">
            <TextBlock x:Name="IsNewToDo" Visibility="Collapsed" />
            <TextBlock x:Name="NoData" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       TextAlignment="Center"
                       Text="暂无数据!"
                       />

            <DataGrid x:Name="BacklogList" 
                      HeadersVisibility="All"  
                      AutoGenerateColumns="False" 
                      ItemsSource="{Binding}"
                      IsReadOnly="True"
                      Initialized="DataGridMenu_Initialized"
                      >
                <DataGrid.ContextMenu>
                    <ContextMenu x:Name="Menu" Width="120">
                        <MenuItem Header="详情" Click="DetailMenu_Click"/>
                        <MenuItem Header="删除" Click="DeleteMenu_Click"/>
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <!--<DataGrid.RowStyle>
                    <Style TargetType="DataGridRow" BasedOn="{StaticResource DataGridRowStyle}">
                        <EventSetter Event="MouseRightButtonDown" Handler="DataGridRow_MouseRightButtonDown" />
                        <Setter Property="Background" Value="White"/>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="{StaticResource BtnBG}"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="False">
                                <Setter Property="Background" Value="White"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.RowStyle>-->



                <DataGrid.RowStyle>
                    <Style TargetType="{x:Type DataGridRow}">
                        <Style.Setters>
                            <Setter Property="SnapsToDevicePixels" Value="true"/>
                            <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
                            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type DataGridRow}">
                                        <Border CornerRadius="8" MouseRightButtonDown="DataGridRow_MouseRightButtonDown" Margin="0,0,0,5" BorderBrush="Black" BorderThickness="0" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                                            <Border.Style>
                                                <Style TargetType="Border">
                                                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                                </Style>
                                            </Border.Style>
                                            <SelectiveScrollingGrid>
                                                <SelectiveScrollingGrid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </SelectiveScrollingGrid.ColumnDefinitions>
                                                <SelectiveScrollingGrid.RowDefinitions>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="Auto"/>
                                                </SelectiveScrollingGrid.RowDefinitions>
                                                <DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                <Path Name="Cross" Grid.ColumnSpan="2" Visibility="Collapsed" Margin="10,0,10,0" Data="M0,0.5 L1,0.5" Stretch="Fill" Stroke="Gray" StrokeThickness="1" Opacity="0.5" />
                                            </SelectiveScrollingGrid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <DataTrigger Binding="{Binding ElementName=IsNewToDo, Path=Text}" Value="N">
                                                <Setter TargetName="Cross" Property="Visibility" Value="Visible"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding ElementName=IsNewToDo, Path=Text}" Value="Y">
                                                <Setter TargetName="Cross" Property="Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style.Setters>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#E5E5E2" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.RowStyle>


                <DataGrid.CellStyle>
                    <Style TargetType="DataGridCell" BasedOn="{StaticResource DataGridCellStyle}">
                        <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        <Setter Property="Background" Value="Transparent"/>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Transparent"/>
                                <Setter Property="Foreground" Value="Black"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource DataGridColumnHeaderStyle}">
                        <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    </Style>
                </DataGrid.ColumnHeaderStyle>

                <DataGrid.Background>
                    <SolidColorBrush Color="Transparent"/>
                </DataGrid.Background>
                <DataGrid.Columns>
                    <DataGridTextColumn Width="120" Binding="{Binding Title}" Header="待办任务"/>
                    <DataGridTextColumn Width="210" Binding="{Binding Msg}" Header="待办详情"/>
                    <DataGridTextColumn Width="147" Binding="{Binding ExeTime}" Header="待办时间"/>
                    <DataGridTextColumn Width="147" Binding="{Binding DoneTime}" Header="完成时间"/>
                </DataGrid.Columns>
            </DataGrid>
            <StackPanel hc:Growl.GrowlParent="True" hc:Growl.Token="DeleteConfirm" VerticalAlignment="Center" Margin="0,10,10,50"/>
        </Grid>
    </hc:SimplePanel>
</UserControl>
