<fw:BaseWindow x:Class="Com.FirmLib.UI.Maintainer.WinUpdateProductType"
             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:fw="http://schemas.FWind/xaml"
             xmlns:uc="clr-namespace:Com.FirmLib.UI.Common"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:dgx="urn:tom-englert.de/DataGridExtensions"
             Name="this" Title="编辑维修商型号"
             Height="550" Width="500" WindowStartupLocation="CenterOwner">
    <fw:BaseWindow.Resources>
        <fw:BindingProxy x:Key="DATA" Data="{Binding}"></fw:BindingProxy>
        <Style TargetType="DataGridRow">
            <Setter Property="Height" Value="30"></Setter>
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex"
                             Value="0">
                    <Setter Property="Background" Value="White" />
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex"
                             Value="1">
                    <Setter Property="Background" Value="#FFE6E3DD" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </fw:BaseWindow.Resources>

    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Margin="0,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <ListBox Grid.Row="0" Grid.Column="0" BorderThickness="0" ItemsSource="{Binding Root.Items}" SelectedItem="{Binding Root.CurrentItem,Mode=TwoWay}" >
                <ListBox.ItemsPanel >
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" Width="{Binding Path=Width,RelativeSource={RelativeSource AncestorType=ListBox}}"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="|" x:Name="Txt"></TextBlock>
                                        <TextBlock Margin="5,0,5,0" x:Name="TXTN" Text="{Binding RefItem.Name}" Foreground="Blue"  TextDecorations="Underline">
                                        </TextBlock>

                                    </StackPanel>
                                    <ControlTemplate.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}"
                                                 Value="{x:Null}">
                                            <Setter TargetName="Txt" Property="Visibility" Value="Collapsed"></Setter>
                                        </DataTrigger>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="TXTN" Property="Foreground" Value="Black"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

            <!--<ToggleButton Grid.Column="1"   VerticalAlignment="Top"   Height="23"   Margin="0" Content="编辑型号">
                <ToggleButton.Style>
                    <Style TargetType="ToggleButton">
                        <Style.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Content" Value="取消编辑"></Setter>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter Property="Content" Value="编辑型号"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
                </ToggleButton>-->
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <DataGrid x:Name="BrandGrid" Grid.Column="0" BorderThickness="1" BorderBrush="Black"  AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Root.CurrentItem.Nodes}" SelectedItem="{Binding Root.CurrentItem.CurrentItem}"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  VerticalScrollBarVisibility="Auto"
                  HorizontalScrollBarVisibility="Auto"
                  SelectionUnit="FullRow"
                  HeadersVisibility="Column" 
                  CanUserSortColumns="True"      dgx:DataGridFilter.IsAutoFilterEnabled="True"
                  CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                  AlternationCount="2">
                <DataGrid.Columns>
                    <fw:TDataGridTextColumn Width="*" Header="品牌名" Binding="{Binding RefItem.Name}" IsReadOnly="True"></fw:TDataGridTextColumn>
                </DataGrid.Columns>

            </DataGrid>

            <DataGrid x:Name="ProductGrid" Grid.Column="1" BorderThickness="1" BorderBrush="Black"   AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Root.CurrentItem.CurrentItem.Nodes}" SelectedItem="{Binding Root.CurrentItem.CurrentItem.CurrentItem}"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  VerticalScrollBarVisibility="Auto"
                  HorizontalScrollBarVisibility="Auto"
                  SelectionUnit="FullRow"
                  HeadersVisibility="Column" 
                  CanUserSortColumns="True"   
                  CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                  AlternationCount="2">
                <DataGrid.Columns>
                    <fw:TDataGridTextColumn Width="*" Header="产品名" Binding="{Binding RefItem.Name}" IsReadOnly="True"></fw:TDataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>

                <DataGrid x:Name="ProductTypeGrid" Grid.Row="0" BorderThickness="1" BorderBrush="Black"  AutoGenerateColumns="False" SelectionMode="Single"  FrozenColumnCount="1" ItemsSource="{Binding Root.CurrentItem.CurrentItem.CurrentItem.Nodes}" SelectedItem="{Binding Root.CurrentItem.CurrentItem.CurrentItem.CurrentItem,Mode=OneWay}"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      VerticalScrollBarVisibility="Auto"
                      HorizontalScrollBarVisibility="Auto"
                      SelectionUnit="FullRow"
                      HeadersVisibility="Column" 
                      CanUserSortColumns="True"   
                      CellStyle="{StaticResource ResourceKey={x:Static uc:CommonStyles.DataGridCellKey}}"
                      AlternationCount="2">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Visibility="{Binding Data.IsEdit,Source={StaticResource ResourceKey=DATA},Converter={x:Static fw:ConverterFactory.BooleanToVisibility}}">
                            <DataGridTemplateColumn.Header>
                                <CheckBox IsChecked="{Binding Data.Root.CurrentItem.CurrentItem.CurrentItem.IsChecked,Source={StaticResource ResourceKey=DATA}}"></CheckBox>
                            </DataGridTemplateColumn.Header>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding IsChecked,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center"></CheckBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <fw:TDataGridTextColumn Width="*" Header="型号" Binding="{Binding RefItem.Name}" IsReadOnly="True" ></fw:TDataGridTextColumn>

                    </DataGrid.Columns>
                </DataGrid>

                <StackPanel Height="35" Grid.Row="1" Visibility="{Binding IsEdit,Converter={x:Static fw:ConverterFactory.BooleanToVisibility}}" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Button Command="{Binding Commands.UpdateProductTypeCommand}" CommandParameter="{Binding ElementName=this}"  Style="{StaticResource ResourceKey={x:Static uc:CommonStyles.ButtonKey}}"   Height="23" Width="100"  Margin="0" Content="确定" Click="btnOK_Click"/>

                </StackPanel>
            </Grid>

        </Grid>
    </Grid>
</fw:BaseWindow>

