<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:Controls="clr-namespace:Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Controls"
					xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		            xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
					xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
					mc:Ignorable="d">


    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime;component/Resources/Converters.xaml" />
        <ResourceDictionary Source="/Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime;component/Resources/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="ElementModelContextMenuButton" TargetType="{x:Type Controls:ContextMenuButton}">
        <Canvas x:Name="canvas" Height="12" Width="12" Background="{TemplateBinding Background}">
        	<Canvas.Effect>
				<DropShadowEffect ShadowDepth="0" BlurRadius="0" Opacity="0"/>
			</Canvas.Effect>
        	<Rectangle x:Name="rectangle" Width="12" Height="12" Margin="0" Opacity="0" Fill="Blue" IsHitTestVisible="True" Canvas.Left="0" Canvas.Top="0" />
        	<Viewbox x:Name="viewbox" Width="4.085" Height="3.911" Canvas.Left="6.614" Canvas.Top="6.47">
        		<Canvas Width="6.794" Height="6.896">
        			<Path x:Name="path1" Width="9.794" Height="10.135" Canvas.Left="-1.998" Canvas.Top="-2.237" Stretch="Fill" StrokeThickness="2" StrokeLineJoin="Round" Stroke="{DynamicResource ElementContextButtonStroke}" Data="F1 M 5.79369,1.00426L 5.79369,5.89604L 1.1338,5.89604"/>
        			<Path x:Name="path2" Width="9.603" Height="9.925" Canvas.Left="-1.998" Canvas.Top="-2.099" Stretch="Fill" StrokeThickness="2" StrokeLineJoin="Round" Stroke="{DynamicResource ElementContextButtonStroke}" Data="F1 M 5.60292,5.82433L 0.999999,1"/>
        		</Canvas>
        	</Viewbox>
        	<Path x:Name="path" Stretch="Fill" StrokeThickness="2" StrokeLineJoin="Round" Stroke="{DynamicResource ElementContextButtonStroke}" Data="F1 M 4.32661,14.7089L 4.32661,4.92529L 13.6607,4.9253" Width="9.081" Height="9.022" Canvas.Left="1.497" Canvas.Top="1.331"/>
        </Canvas>
    	<ControlTemplate.Triggers>
    		<Trigger Property="IsMouseOver" Value="True">
    			<Setter Property="Stroke" TargetName="path" Value="{DynamicResource ElementContextMenuButtonStrokeHighlight}">
    			</Setter>
    			<Setter Property="Stroke" TargetName="path1"  Value="{DynamicResource ElementContextMenuButtonStrokeHighlight}" >
    			</Setter>
    			<Setter Property="Stroke" TargetName="path2" Value="{DynamicResource ElementContextMenuButtonStrokeHighlight}" >
    			</Setter>
    			<Setter Property="Background" TargetName="canvas" Value="{DynamicResource ElementContextMouseOverBrush}"/>
				<Setter Property="Effect" TargetName="canvas">
					<Setter.Value>
						<DropShadowEffect ShadowDepth="1" BlurRadius="1" Opacity="1"/>
					</Setter.Value>
				</Setter>
    		</Trigger>
    	</ControlTemplate.Triggers>
    </ControlTemplate>


    <Style TargetType="{x:Type Controls:ElementModelContainer}">
        <Setter Property="Margin" Value="12,0,12,6" />
        <Setter Property="Background" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ElementModelContainer}">
                    <Grid ScrollViewer.VerticalScrollBarVisibility="Disabled"
						  IsSharedSizeScope="True">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Border x:Name="contentBorder"
								BorderBrush="{DynamicResource LightGreyBorderBrush}"
								BorderThickness="1"
								Background="#FFF0F0F0"
								Padding="3,3,1,3"
								VerticalAlignment="Top"
								d:LayoutOverrides="Width, Height"
								Grid.ColumnSpan="2">

                            <ContentControl 
                                x:Name="Title" 
                                Focusable="False"
                                HorizontalAlignment="Stretch" 
                                HorizontalContentAlignment="Stretch" >
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="24" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <ToggleButton Template="{DynamicResource ExpanderToggleButton}"
                                            x:Name="ShowProperties"
                                            Focusable="False"
									        Background="{DynamicResource NormalBrush}"
									        IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
									        OverridesDefaultStyle="True" 
                                            Grid.Column="0">

                                        <ToggleButton.Visibility>
                                            <Binding Path="Properties" 
                                                 Converter="{StaticResource PropertiesToVisibilityConverter}" 
                                                 FallbackValue="Collapsed">
                                            </Binding>
                                        </ToggleButton.Visibility>
                                    </ToggleButton>

                                    <TextBlock Text="{Binding Name, Mode=OneWay}"
				                           HorizontalAlignment="Left"
				                           VerticalAlignment="Center"
				                           Background="{x:Null}"
				                           Margin="5,0,15,0"
				                           Grid.Column="1"/>

                                    <Controls:ContextMenuButton
                                        x:Name="ContextMenuButton"
                                        HorizontalAlignment="Right" 
                                        Margin="0,0,0,-2" 
                                        VerticalAlignment="Bottom" 
                                        Content="ContextMenuButton" 
                                        Grid.Column="1" 
                                        Visibility ="Visible"
                                        Opacity="0"
                                        TargetElement="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                        Template="{StaticResource ElementModelContextMenuButton}" Width="11" Height="11" Padding="0"
                                        />
                                </Grid>
                            </ContentControl>
                        </Border>

                        <Border x:Name="PART_Adorner"
								BorderBrush="{DynamicResource AdornerStrokeBrush}"
								BorderThickness="1"
								Background="{DynamicResource AdornerFillBrush}"
								Visibility="Collapsed"
								VerticalAlignment="Top"
								IsHitTestVisible="False"
								Height="{Binding ElementName=contentBorder, Path=ActualHeight, Mode=OneWay}"
								Grid.ColumnSpan="2" />

                        <Border Background="{StaticResource PopupBackground}"
									BorderBrush="{StaticResource LightGreyBorderBrush}"
									BorderThickness="1"
									Padding="2"
									Grid.ColumnSpan="3"
									Grid.Row="1"
									Visibility="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">

                            <ItemsControl Focusable="False" Grid.IsSharedSizeScope="True" x:Name="ElementProperties">
                                <ItemsControl.Resources>
                                    <CollectionViewSource x:Key="SortedProperties" Source="{Binding Properties}">
                                        <CollectionViewSource.SortDescriptions>
                                            <ComponentModel:SortDescription PropertyName="BindableProperty.Category" />
                                            <ComponentModel:SortDescription PropertyName="BindableProperty.DisplayName" />
                                        </CollectionViewSource.SortDescriptions>
                                    </CollectionViewSource>
                                </ItemsControl.Resources>
                                <ItemsControl.ItemsSource>
                                    <Binding Source="{StaticResource SortedProperties}" />
                                </ItemsControl.ItemsSource>
                                <ItemsControl.Template>
                                    <ControlTemplate>
                                        <Grid HorizontalAlignment="Stretch" x:Name="ElementPropertyGrid" 
                                              Controls:GridSplitterKeyAccelerator.TargetColumn="1"
                                              Controls:GridSplitterKeyAccelerator.DecrementKeyGesture="Alt+Left"
                                              Controls:GridSplitterKeyAccelerator.IncrementKeyGesture="Alt+Right">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="12" />
                                                <ColumnDefinition MinWidth="50" Width="75" SharedSizeGroup="PropLabel"/>
                                                <ColumnDefinition MinWidth="50" Width="175*" />
                                            </Grid.ColumnDefinitions>

                                            <GridSplitter Focusable="False"
                                                          Grid.Column="1" 
                                                          HorizontalAlignment="Right" 
                                                          Width="2"
                                                          ResizeDirection="Columns" 
                                                          ShowsPreview="False" />

                                            <VirtualizingStackPanel 
                                                Grid.ColumnSpan="3"
                                                IsItemsHost="True" />
                                        </Grid>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <ContentControl Focusable="False" Content="{Binding}" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>               		
                		<Trigger Property="IsMouseOver" Value="true">
                			<Setter TargetName="ContextMenuButton"
                				Property="Opacity"
                				Value="1" />
                		</Trigger>
                	</ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>