<Window x:Class="Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ComponentModel.Editors.TypeBrowser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:browser="clr-namespace:Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ComponentModel.Editors"
        xmlns:converters="clr-namespace:Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Converters"
        Title="{Binding Title}" 
        Height="386" Width="567"
        ShowInTaskbar="False"
        FocusManager.FocusedElement="{Binding ElementName=TypeName}"        
        Name="Browser">
    <Window.Resources>
        <converters:NullToBooleanConverter x:Key="NullToBooleanConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </Window.Resources>

    <DockPanel>

        <DockPanel DockPanel.Dock="Bottom" LastChildFill="False" Margin="5, 5, 5, 5">
            <Button x:Name="AddFromGac" 
                    DockPanel.Dock="Left" 
                    MinWidth="100" 
                    Click="AddFromGac_Click"
                    AutomationProperties.AutomationId="AddFromGac">
                <Button.Visibility>
                    <Binding ElementName="Browser" Path="SupportsAssemblyLoading" Mode="OneWay" Converter="{StaticResource BooleanToVisibilityConverter}" />
                </Button.Visibility>
                Add from GAC
            </Button>
            <Button x:Name="AddFromFile" 
                    DockPanel.Dock="Left" 
                    MinWidth="100" 
                    Margin="5,0, 0, 0" 
                    Click="AddFromFile_Click"
                    AutomationProperties.AutomationId="AddFromFile">
                <Button.Visibility>
                    <Binding ElementName="Browser" Path="SupportsAssemblyLoading" Mode="OneWay" Converter="{StaticResource BooleanToVisibilityConverter}" />
                </Button.Visibility>
                Add from File
            </Button>
            <Button x:Name="Cancel" 
                    DockPanel.Dock="Right" 
                    MinWidth="100" 
                    Margin="5,0,0,0" 
                    IsCancel="True"
                    AutomationProperties.AutomationId="Cancel">
                Cancel
            </Button>
            <Button x:Name="Ok" 
                    DockPanel.Dock="Right" 
                    MinWidth="100" 
                    Margin="0" 
                    IsDefault="True" 
                    IsEnabled="{Binding ConcreteType, Converter={StaticResource NullToBooleanConverter}}" 
                    Click="Ok_Click"
                    AutomationProperties.AutomationId="OK">
                OK
            </Button>
        </DockPanel>

        <DockPanel LastChildFill="True" DockPanel.Dock="Top">
            <DockPanel DockPanel.Dock="Top" Margin="5,10,5,0">
                <Label Margin="0,0,5,0">Type name</Label>
                <TextBox Name="TypeName" 
                     HorizontalAlignment="Stretch" 
                     Margin="5,0,0,0" 
                     Text="{Binding TypeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                     AutomationProperties.AutomationId="TypeName"/>
            </DockPanel>

            <Grid DockPanel.Dock="Top" 
              Margin="5,5,5,5"
              Visibility="{Binding HasGenericParameters, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
                <ItemsControl ItemsSource="{Binding GenericTypeParameters}">
                </ItemsControl>
            </Grid>

            <TreeView x:Name="TypesTree" 
                  ItemsSource="{Binding AssemblyGroups}" 
                  Margin="5" 
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  AutomationProperties.AutomationId="TypesTree">

                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=Visibility}" Value="Collapsed">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Setter Property="IsEnabled" Value="false" />
                            </DataTrigger>
                        </Style.Triggers>
                        <EventSetter Event="TreeViewItem.MouseDoubleClick" Handler="TypesTree_MouseDoubleClick"/>
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                        <Setter Property="FontWeight" Value="Normal" />
                    </Style>
                </TreeView.ItemContainerStyle>

                <TreeView.Resources>
                    <HierarchicalDataTemplate 
                  DataType="{x:Type browser:AssemblyGroupNode}" 
                  ItemsSource="{Binding Assemblies}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding DisplayName}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>

                    <HierarchicalDataTemplate 
                  DataType="{x:Type browser:AssemblyNode}" 
                  ItemsSource="{Binding Namespaces}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding DisplayName}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>

                    <HierarchicalDataTemplate 
                  DataType="{x:Type browser:NamespaceNode}" 
                  ItemsSource="{Binding Types}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding DisplayName}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>

                    <DataTemplate 
                  DataType="{x:Type browser:TypeNode}" >
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding DisplayName}" />
                        </StackPanel>
                    </DataTemplate>
                </TreeView.Resources>
            </TreeView>
        </DockPanel>

    </DockPanel>

</Window>
