<UserControl
    x:Class="MECF.Framework.UI.Client.CenterViews.Core.UserControls.DataViewDataGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
    xmlns:converter="clr-namespace:MECF.Framework.UI.Client.Ctrlib.Converter"
    xmlns:converters="clr-namespace:Aitex.Core.UI.Converters;assembly=MECF.Framework.UI.Core"
    xmlns:converters1="clr-namespace:Sicentury.Core.Converters;assembly=Sicentury.Core"
    xmlns:cv="clr-namespace:MECF.Framework.UI.Core.Converters;assembly=MECF.Framework.UI.Core"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:extendedControls="clr-namespace:MECF.Framework.UI.Core.ExtendedControls;assembly=MECF.Framework.UI.Core"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:local="clr-namespace:MECF.Framework.UI.Client.CenterViews.Core.UserControls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:micro="clr-namespace:Caliburn.Micro"
    xmlns:lex="http://wpflocalizeextension.codeplex.com"
    d:DesignHeight="450"
    d:DesignWidth="2000"
    mc:Ignorable="d"
    lex:LocalizeDictionary.DesignCulture="en"
    lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
    lex:ResxLocalizationProvider.DefaultDictionary="lang_common">

    <!--
        DataContext MUST BE "ChartingLineSeriesCollection"
    -->
    <UserControl.Resources>
        <converters:LineColorConverter x:Key="colorConverter" />
        <cv:BoolCollapsedConverter x:Key="BoolVisibility" />
        <converters1:ParameterNodeStatisticToStringConverter x:Key="DoubleToString" />
    </UserControl.Resources>
    <DataGrid
        AlternationCount="2"
        AutoGenerateColumns="False"
        BorderThickness="1"
        CanUserAddRows="False"
        CanUserResizeColumns="True"
        CanUserResizeRows="False"
        CanUserSortColumns="False"
        ColumnHeaderHeight="30"
        FontFamily="Arial"
        FontSize="12"
        IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsEnabled}"
        ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=ItemsSource}">
        <DataGrid.Resources>
            <extendedControls:BindingProxy x:Key="proxy" Data="{Binding RelativeSource={RelativeSource AncestorType=local:DataViewDataGrid, Mode=FindAncestor}}" />
        </DataGrid.Resources>
        <DataGrid.Columns>
            <DataGridTemplateColumn MinWidth="60">
                <DataGridTemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                            <CheckBox x:Name="cbVisibleInColumnHeader" IsChecked="{Binding Data.IsVisibleInColumnHeader, Mode=TwoWay, Delay=1, Source={StaticResource proxy}}" />
                            <TextBlock
                                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                                Margin="3,0,0,0"
                                VerticalAlignment="Bottom"
                                Text="{lex:Loc ID_TXT_Visible}"/>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox
                            x:Name="cbVisibleInRow"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            IsChecked="{Binding IsVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                                    MinWidth="100" Header="{lex:Loc ID_TXT_Name}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            Margin="5,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding DataName}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                MinWidth="100" Header="{lex:Loc ID_TXT_Color}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Border
                            x:Name="btnChangeSeriesColor"
                            Width="30"
                            Height="20"
                            Margin="0,1"
                            Background="{Binding Stroke, Converter={StaticResource colorConverter}}"
                            Cursor="Hand"
                            PreviewMouseUp="BtnChangeSeriesColor_OnPreviewMouseUp" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                MinWidth="100" Header="{lex:Loc ID_TXT_Factor}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Text="{Binding DataFactor}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <controls:TextBoxEx
                            Width="80"
                            Margin="5,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            AllowBackgroundChange="False"
                            FontFamily="Arial"
                            FontSize="14"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding DataFactor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                MinWidth="100" Header="{lex:Loc ID_TXT_Offset}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Text="{Binding DataOffset}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <controls:TextBoxEx
                            Width="80"
                            Margin="5,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            AllowBackgroundChange="False"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding DataOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                MinWidth="60" Header="{lex:Loc ID_TXT_Width}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Text="{Binding LineThickness}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <controls:TextBoxEx
                            Width="80"
                            Margin="5,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            AllowBackgroundChange="False"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding LineThickness, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                MinWidth="100"
                Header="{lex:Loc ID_TXT_Min}"
                Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding BackendParameterNode.MinValue, Converter={StaticResource DoubleToString}}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                MinWidth="100"
                Header="{lex:Loc ID_TXT_Max}"
                Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding BackendParameterNode.MaxValue, Converter={StaticResource DoubleToString}}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn
                lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                MinWidth="100"
                Header="{lex:Loc ID_TXT_Average}"
                Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Foreground="{StaticResource FG_Black}"
                            Text="{Binding BackendParameterNode.AverageValue, Converter={StaticResource DoubleToString}}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn MinWidth="120">
                <DataGridTemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <Button
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                            x:Name="btnExportAll"
                            Width="85"
                            Height="22"
                            Padding="0"
                            Click="BtnExportAll_OnClick"
                            Content="{lex:Loc ID_BTN_ExportAll_Content}" />
                    </DataTemplate>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                            x:Name="btnExport"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Cursor="Hand"
                            Foreground="DarkBlue"
                            PreviewMouseUp="BtnExport_OnPreviewMouseUp"
                            Text="{lex:Loc ID_BTN_Export_Content}"
                            TextDecorations="Underline" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn MinWidth="120">
                <DataGridTemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <Button
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                            x:Name="btnDeleteAll"
                            Width="85"
                            Height="22"
                            Padding="0"
                            Click="BtnDeleteAll_OnClick"
                            Content="{lex:Loc ID_BTN_DeleteAll_Content}" />
                    </DataTemplate>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                            x:Name="btnDelete"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Cursor="Hand"
                            Foreground="DarkBlue"
                            PreviewMouseUp="BtnDelete_OnPreviewMouseUp"
                            Text="{lex:Loc ID_BTN_Delete_Content}"
                            TextDecorations="Underline" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn MinWidth="120">
                <DataGridTemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <Button
                lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                x:Name="btnSaveAllImage"
                Width="85"
                Height="22"
                Padding="0"
                Click="BtnSaveAllImage_OnClick"
                Content="SaveAllImage" />
                    </DataTemplate>
                </DataGridTemplateColumn.HeaderTemplate>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock
                lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
                x:Name="btnSaveImage"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Cursor="Hand"
                Foreground="DarkBlue"
                PreviewMouseUp="BtnSaveImage_OnPreviewMouseUp"
                Text="SaveImage"
                TextDecorations="Underline" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn Width="*" />
        </DataGrid.Columns>
    </DataGrid>
</UserControl>
