<Window x:Class="C1ComboBoxMutliSelectionSample2010.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:C1ComboBoxMutliSelectionSample2010"
        xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
        mc:Ignorable="d"
        Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <Grid.Resources>
            <Style x:Key="SampleTextBlockStyle" TargetType="TextBlock">
                <Setter Property="Margin" Value="5"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            <Style x:Key="SampleListBoxStyle" TargetType="ListBox">
                <Setter Property="Margin" Value="5"/>
                <Setter Property="BorderThickness" Value="2"/>
            </Style>
            <Style x:Key="SampleComboBoxStyle" TargetType="{x:Type c1:C1ComboBox}">
                <Setter Property="Margin" Value="5"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="SelectionMode" Value="Multiple"/>
                <Setter Property="DisplayMemberPath" Value="Name"/>
                <Setter Property ="MultipleSelectionSeparator" Value=", "/>
            </Style>
            <Style TargetType="c1:C1ComboBoxItem" x:Key="C1ComboBoxCheckItemStyle">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="c1:C1ComboBoxItem">
                            <Grid x:Name="Root">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="Disabled" />
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="MouseOverElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Unfocused" />
                                        <VisualState x:Name="Focused" >
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="FocusElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualState x:Name="Unselected" />
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="SelectedElement" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" />
                                <Border x:Name="SelectedElement" IsHitTestVisible="False" Background="LightBlue" BorderBrush="{TemplateBinding SelectedBackground}" BorderThickness="{TemplateBinding BorderThickness}" Visibility="Collapsed" />
                                <Border x:Name="MouseOverElement" IsHitTestVisible="False" Background="{TemplateBinding MouseOverBrush}" BorderBrush="{TemplateBinding MouseOverBrush}" BorderThickness="{TemplateBinding BorderThickness}"  Visibility="Collapsed" />
                                <Border x:Name="FocusElement" IsHitTestVisible="False" BorderBrush="Black" BorderThickness="{TemplateBinding BorderThickness}" Visibility="Collapsed" />
                                <Grid Margin="{TemplateBinding BorderThickness}">
                                    <CheckBox IsHitTestVisible="False" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected, Mode=TwoWay}" VerticalAlignment="Center" VerticalContentAlignment="Center">
                                        <ContentPresenter x:Name="ContentPresenter" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" />
                                    </CheckBox>
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Style="{StaticResource SampleTextBlockStyle}" Text="Selected Items" />
                <ListBox Style="{StaticResource SampleListBoxStyle}" ItemsSource="{Binding SelectedItems, ElementName=NormalStyleComboBox}" DisplayMemberPath="Name"  Grid.Row="1" />
            </Grid>
            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Style="{StaticResource SampleTextBlockStyle}" Text="Normal Style" />
                <c1:C1ComboBox x:Name="NormalStyleComboBox" Style="{StaticResource SampleComboBoxStyle}" Grid.Row="1" SelectionChanged="OnSelectionChanged"/>
                <TextBlock Style="{StaticResource SampleTextBlockStyle}" Text="CheckBox Style" Grid.Row="2" />
                <c1:C1ComboBox x:Name="CheckBoxStyleComboBox" Style="{StaticResource SampleComboBoxStyle}" Grid.Row="3" ItemContainerStyle="{StaticResource C1ComboBoxCheckItemStyle}" 
                               SelectedItems="{Binding SelectedItems, ElementName=NormalStyleComboBox}"
                />
            </Grid>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock Style="{StaticResource SampleTextBlockStyle}" Text="Operations Infomation" />
            <ListBox x:Name="OperationsInfoListBox" Style="{StaticResource SampleListBoxStyle}" Grid.Row="1" />
        </Grid>
    </Grid>
</Window>
