Opened ContextMenu -> RightClick triggers LeftClickCommand in ViewModel - c#

I have a ContextMenu bound to an HierarchicalDataTemplate that displays a TreeView structure. The ContextMenu also is a HierarchicalDataTemplate that obtains its structure through an ObservableCollection of MenuItemViewModels.
My problem is, that when running the program a RightClick on an already opened ContextMenu unwantedly triggers a LeftClick on the MenuItem - why is that so? What am i missing? I am unable to find the error in code and would appreciate any help.
The XAML for the TreeView:
<HierarchicalDataTemplate x:Key="TreeHierarchicalDataTemplate" DataType="{x:Type model:TreeNodeBaseViewModel}" ItemsSource="{Binding Path=SubItems, UpdateSourceTrigger=PropertyChanged}" ItemContainerStyle="{StaticResource MenuItemTemplateItemContainerStyle}">
<!--...-->
</HierarchicalDataTemplate>
<Style x:Key="MenuItemTemplateItemContainerStyle" TargetType="{x:Type TreeViewItem}">
<Setter Property="ContextMenu" Value="{DynamicResource MenuItemContextMenu}"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Setter Property="AllowDrop" Value="{Binding IsDropAllowed}"/>
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
<Setter Property="Tag" Value="{Binding}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsVisible}" Value="False">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<Trigger Property="beh:TreeNodeMouseOver.IsMouseDirectlyOverItem" Value="True">
<Setter Property="Background" Value="AliceBlue" />
</Trigger>
</Style.Triggers>
</Style>
The XAML for the ContextMenu:
<ContextMenu x:Key="MenuItemContextMenu" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=TreeViewModel.MenuItems, UpdateSourceTrigger=PropertyChanged}">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type model:MenuItemBaseViewModel}" ItemsSource="{Binding Path=SubItems, UpdateSourceTrigger=PropertyChanged}">
<TextBlock Text="{Binding Header}"/>
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="ToolTip" Value="{Binding ToolTip}"/>
<Setter Property="IsHitTestVisible" Value="True"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Setter Property="Command" Value="{Binding MouseLeftButtonDownCommand}"/> <!--LeftClick is bound to ViewModel here, but RightClick is not even defined anywhere in MenuItem or ViewModel-->
<Style.Triggers>
<DataTrigger Binding="{Binding VisibleSubItems}" Value="0">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid Margin="-1">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
<ColumnDefinition Width="13"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
<Border x:Name="GlyphPanel" BorderBrush="#FF26A0DA" BorderThickness="1" Background="#3D26A0DA" ClipToBounds="False" HorizontalAlignment="Center" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22">
<Path x:Name="Glyph" Data="F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z" Fill="#FF212121" FlowDirection="LeftToRight" Height="11" Width="10"/>
</Border>
<ContentPresenter x:Name="menuHeaderContainer" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="2" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<TextBlock x:Name="menuGestureText" Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
<Button Grid.Column="5" Margin="2" Command="{Binding EditCommand}" Visibility="{Binding IsEditVisible, Converter={StaticResource BooleanToVisibilityConverter}}" Background="Transparent" BorderThickness="0">
<iconPacks:PackIconMaterialLight Width="14" Height="14" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center" Kind="Cog" />
</Button>
<Button Grid.Column="6" Margin="2" Command="{Binding HelpCommand}" Visibility="{Binding IsInfoVisible, Converter={StaticResource BooleanToVisibilityConverter}}" Background="Transparent" BorderThickness="0">
<iconPacks:PackIconMaterial Width="14" Height="14" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Kind="InformationOutline" />
</Button>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter Property="Background" TargetName="templateRoot" Value="#3D26A0DA"/>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="#FF26A0DA"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
<Setter Property="Fill" TargetName="Glyph" Value="#FF707070"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsHighlighted" Value="True"/>
<Condition Property="IsEnabled" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="templateRoot" Value="#0A000000"/>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="#21000000"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding IsVisible}" Value="false">
<Setter Property="MenuItem.Visibility" Value="Collapsed"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconSimpleIconsKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource Simple}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconEntypoKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource Entypo}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconFontAwesomeKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource FontAwesome}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconMaterialKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource Material}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconMaterialLightKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource MaterialLight}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconModernKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource Modern}"/>
</DataTrigger>
<DataTrigger Binding="{Binding PackIcon.IconType}" Value="{x:Type iconPacks:PackIconOcticonsKind}">
<Setter Property="MenuItem.Icon" Value="{StaticResource Octicons}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.ItemContainerStyle>
<i:Interaction.Behaviors>
<beh:EventToCommandBehavior Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=TreeViewModel.ContextMenuOpenedCommand}" Event="Opened" PassArguments="True" />
</i:Interaction.Behaviors>
</ContextMenu>

That behavior is by design. If you want seperate left/right click handlers for your menu items then you need to add the corresponding MouseBindings to your MenuItem InputBindings collection. If you need to do that in a style then you can use the Attach behavior in this question.
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="behaviors:Attach.InputBindings">
<Setter.Value>
<InputBindingCollection>
<MouseBinding Gesture="LeftClick" Command="{Binding LeftClickCommand}" />
<MouseBinding Gesture="RightClick" Command="{Binding RightClickCommand}" />
</InputBindingCollection>
</Setter.Value>
</Setter>
</Style>
</ContextMenu.ItemContainerStyle>

Related

Why does double clicking on the DataGrid Header not automaticly set the widht of the Column Content lenght?

I have an DataGrid on which I used a style which looks like that:
<Style x:Key="DataGridStyle" TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="#FF688CAF"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<Border Background="{TemplateBinding Background}" CornerRadius="20" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="DG_ScrollViewer" Focusable="false">
<ScrollViewer.Template>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Command="{x:Static DataGrid.SelectAllCommand}" Focusable="false" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" Grid.ColumnSpan="2" Grid.Row="1"/>
<ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
<Grid Grid.Column="1" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
</Grid>
</Grid>
</ControlTemplate>
</ScrollViewer.Template>
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true"/>
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</MultiTrigger>
</Style.Triggers>
</Style>
and the other DataGrid Code:
<DataGrid Style="{StaticResource DataGridStyle}" Margin="10" SelectionUnit="CellOrRowHeader" AutoGenerateColumns="False"
SelectionMode="Single"
ItemsSource="{Binding Path=collRMA, ElementName=vmRMA,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
x:Name="datagrid" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="True"
GridLinesVisibility="None" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="380"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding artNumber}" Header="artNumber" Visibility="Hidden" Width="*"/>
<DataGridTextColumn Binding="{Binding position}" Header="Pos" Width="0.5*"/>
<DataGridTextColumn Binding="{Binding description}" Header="description" Width="*"/>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="Copy"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}" x:Name="test" >
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Height" Value="30"/>
<Setter Property="FontSize" Value="15"/>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="Padding" Value="10 0 0 0"/>
<EventSetter Event="PreviewMouseDoubleClick" Handler="DataGridColumnHeader_PreviewMouseDoubleClick"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid x:Name="insideHeader" Background="Transparent">
<Border x:Name="borderHeader" BorderThickness="0"
CornerRadius="10"
Background="White"
Padding="10,0,0,0"
>
<ContentPresenter />
</Border>
<!--<Thumb HorizontalAlignment="Right"
Grid.Column="1"
Name="PART_HeaderGripper"
Margin="0,4,0,4"
Width="2"/>-->
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryBlueColor}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="borderHeader" Property="Background" Value="{DynamicResource SecundaryGrayColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontFamily" Value="sans-serif"/>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="#333333"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="insideBorder" Background="Transparent" BorderThickness="0 2 0 1" BorderBrush="#dddddd">
<Border x:Name="BorderCell" BorderThickness="0"
CornerRadius="6"
Background="White"
Padding="8,5,0,5"
Margin="2">
<ContentPresenter/>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryBlueColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
</DataGrid>
The Problem which I got now, is that when I double Click the Column Header, the Content of the Cell not widht the Content. So the widht doesnt Fit the Content of the Cell if the Cells Content longer then the actual Cell widht. Anyone an Idea why the Cell Content dont update the Widht when I double click the Column Header?

Stop combobox from closing

I am using custom control, MultiSelectComboBox that is already placed on code project (https://www.codeproject.com/Articles/563862/Multi-Select-ComboBox-in-WPF). This combobox has checkboxes inside of it. I am trying to achieve following:
When combobox opens, I want to close it by clicking only on Ok/Cancel button. Cancel will close it and none of the checkboxes will be checked. I don't want it to close when I click with my mouse on a window or anywhere else besides Ok/Cancel button.
Here is the part of the code:
<ComboBox x:Name="cmbMultiSelect" Style="{StaticResource MultiSelectComboBoxStyler}">
<ComboBox.ToolTip >
<ToolTip DataContext="{Binding Path=PlacementTarget.Parent, RelativeSource={x:Static RelativeSource.Self}}">
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource CommmaToNewLineConverter}}"/>
</ToolTip>
</ComboBox.ToolTip>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="cbSelector"
Content="{Binding Title, UpdateSourceTrigger=PropertyChanged}"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
Click="cbSelector_OnClick"/>
</DataTemplate>
</ComboBox.ItemTemplate>
Now, here it my style, MultiSelectComboBoxStyler:
<Style x:Key="MultiSelectComboBoxStyler" TargetType="{x:Type ComboBox}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox/>
<!-- Do not really need to specify in this instance, since the ItemTemplate is going to be overwritten -->
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton"
Grid.Row="0"
Grid.Column="0"
Content="{Binding Path=Text, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Focusable="false"
ClickMode="Press"
HorizontalContentAlignment="Left">
<ToggleButton.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="18"/>
</Grid.ColumnDefinitions>
<Border x:Name="Border"
Grid.ColumnSpan="2"
CornerRadius="2"
Background="White"
BorderBrush="{StaticResource NormalBorderBrush}"
BorderThickness="1,1,1,1" />
<Border x:Name="BorderComp"
Grid.Column="0"
CornerRadius="2"
Margin="1"
Background="White"
BorderBrush="{StaticResource NormalBorderBrush}"
BorderThickness="0,0,0,0" >
<TextBlock x:Name="txtOnToggleButton"
Background="White"
Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
TextTrimming="WordEllipsis"
TextWrapping="Wrap"
Padding="3" />
</Border>
<Path x:Name="Arrow"
Grid.Column="1"
Fill="{StaticResource GlyphBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" />
</Trigger>
<Trigger Property="ToggleButton.IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource MouseHoverBrush}" />
<Setter TargetName="txtOnToggleButton" Property="Background" Value="{StaticResource MouseHoverBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup Name="Popup"
Placement="Bottom"
AllowsTransparency="True"
Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<theme:SystemDropShadowChrome Name="Shdw"
Color="Transparent"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
BorderThickness="1"
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}">
<Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<ScrollViewer Name="DropDownScrollViewer" Margin="4,0,4,30" SnapsToDevicePixels="True">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Name="OpaqueRect"
Height="{Binding ElementName=DropDownBorder,Path=ActualHeight}"
Width="{Binding ElementName=DropDownBorder,Path=ActualWidth}"
Fill="{Binding ElementName=DropDownBorder,Path=Background}" />
</Canvas>
<ItemsPresenter Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
<StackPanel Orientation="Horizontal">
<Button Name="btnOk" Content="Ok" VerticalAlignment="Bottom" Margin="2, 0, 2, 2"
Width="50" Height="25"
Background="{StaticResource WindowBackgroundBrush}"
Command="{Binding OkCommand}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowFilterButtons,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type controls:MultiSelectComboBox}}}"
Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Name="btnCancel" Content="Cancel" VerticalAlignment="Bottom" Margin="2, 0, 2, 2"
Width="50" Height="25"
Background="{StaticResource WindowBackgroundBrush}"
Command="{Binding CancelCommand}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowFilterButtons,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type controls:MultiSelectComboBox}}}"
Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</Grid>
</Border>
</theme:SystemDropShadowChrome>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
<Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.HasDropShadow" Value="true">
<Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5"/>
<Setter TargetName="Shdw" Property="Color" Value="#71000000"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
This is how I use custom control in my view:
<controls:MultiSelectComboBox Width="200" Height="30" HorizontalAlignment="Left" DefaultText="All" ItemsSource="{Binding Chains}" SelectedItems="{Binding SelectedChains, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ShowFilterButtons="True"/>
Although I am pretty new to WPF I was able to understand some things but again this issue is giving me headaches. I am stuck. I know that there is something to do with toggle button but no success in resolve it. I appreciate all the help I can get.
Since you are using multiselectbox control, you should add new dependencyproperty
Also, Popup tag should look like this
IsOpen="{Binding Path=IsChecked, ElementName=ToggleButton}"
While ToggleButton should look like:
IsChecked="{Binding Path=ControlComboBox, Mode=TwoWay,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl},
UpdateSourceTrigger=PropertyChanged}"
Command="{Binding PressedCommand}"
And at the end you should use MultiSelectCombBox in this way:
ControlComboBox="{Binding ManageComboBox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

Difference between Typed Style and setting ItemContainerStyle

I have a Style for my TreeViewItems which at the moment is applied to all because he has no Key.
<Style TargetType="TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<Grid x:Name="gChildren">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle x:Name="HorLin" Grid.Row="0" Height="1" Stroke="Black" SnapsToDevicePixels="True" VerticalAlignment="Bottom" />
<Rectangle x:Name="VerLinUp" Grid.Row="1" Width="1" Height="20" Stroke="Black" SnapsToDevicePixels="True" />
<Border Name="Bd" Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="3" Padding="6" Grid.Row="2" Margin="2,0">
<ContentPresenter Name="PART_Header" ContentSource="Header" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Rectangle x:Name="VerLinDown" Grid.Row="3" Width="1" Height="10" Stroke="Black" SnapsToDevicePixels="True" />
<ItemsPresenter x:Name="itemPresenter" Grid.Row="4" HorizontalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count, Converter={StaticResource IsGreaterThanConv}, ConverterParameter=0}" Value="false">
<Setter TargetName="VerLinDown" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource HasParentMoreChildren}}" Value="false">
<Setter TargetName="HorLin" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsParentTreeViewItem}}" Value="false">
<Setter TargetName="VerLinUp" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsParentTreeViewItem}}" Value="true">
<Setter TargetName="VerLinUp" Property="Height" Value="10" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsFirstOrLastItem}}" Value="2">
<Setter TargetName="HorLin" Property="Width" Value="{Binding ElementName=gChildren, Path=ActualWidth, Converter={StaticResource ArithmeticConverter}, ConverterParameter=/2}" />
<Setter TargetName="HorLin" Property="HorizontalAlignment" Value="Right" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsFirstOrLastItem}}" Value="1">
<Setter TargetName="HorLin" Property="Width" Value="{Binding ElementName=gChildren, Path=ActualWidth, Converter={StaticResource ArithmeticConverter}, ConverterParameter=/2}" />
<Setter TargetName="HorLin" Property="HorizontalAlignment" Value="Left" />
</DataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Panel.Background" Value="{StaticResource SelectedItemAreaBrush}" />
<Setter TargetName="Bd" Property="Border.BorderBrush" Value="{StaticResource SelectedItemBorderBrush}" />
<Setter TargetName="Bd" Property="TextElement.Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel x:Name="spChildren" HorizontalAlignment="Center" IsItemsHost="True" Margin="4,0,4,6" Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
When I leave it like that everything works like I want it too. But if I give my Style a Name and set the ItemContainerStyle on my TreeView it looks different
<Style x:Key="GoodTVI" TargetType="TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<Grid x:Name="gChildren">
Adding my TreeViewItem-Style to my TreeView
TVVerlauf.SetBinding(TreeView.ItemContainerStyleProperty, "GoodTVI");
The Rest of the Style stays exactly the same. This is the only difference but the Result looks completley different.
I give my Style a Name
Actually, you don't.
<Style x:Key="GoodTVI" TargetType="TreeViewItem">
...
That's not a name. That's a key. The Style is a resource. Resources have keys, not names. The two are different. For one thing, resource keys are objects rather than strings. And they're looked up differently, in different places.
Here, you're binding the treeview's ItemContainerStyle property to the GoodTVI property of its DataContext (which should be your viewmodel).
TVVerlauf.SetBinding(TreeView.ItemContainerStyleProperty, "GoodTVI");
Since GoodTVI is a resource key, not the name of a property on the viewmodel, you're naturally not getting good results.
Try this on your TreeView in the XAML:
<TreeView
ItemContainerStyle="{StaticResource GoodTVI}"
...other properties...
>
If you need to do this in C#, try this:
TVVerlauf.ItemContainerStyle = (DataTemplate)TVVerlauf.FindResource("GoodTVI");
Try this:
TVVerlauf.SetBinding(TreeView.StyleProperty, "GoodTVI");

How to change Datagrid row background when clicking on togglebutton inside rowheader?

I am overriding DataGrid row header style, and I’m been hindered with the following two issues:
1.The DataGrid row header contains an Image and a ToggleButton. When the ToggleButton is ‘Checked’ I want to change the background color of the whole row, however I only managed to change the background of the row header and couldn’t figure out a way to fire a trigger on the row level.
2.When a row is selected the row and the header background is set to different background, the other way around does not work. What I need to do is to change the background of the row when the row header is selected
Here is a the style code of the DataGridRowHeader
<Style x:Key="{x:Type DataGridRowHeader}" TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRowHeader}">
<Grid>
<Border Name="RowHeaderBorder"
BorderThickness="0,0,3,0"
Margin="0,0,0,0"
BorderBrush="{StaticResource DataGridRowBorder}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding ImageSource}" RenderOptions.BitmapScalingMode="HighQuality" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ToggleButton x:Name="tglButton" Visibility="{Binding ActiveCall}" Grid.Column="1" Content="Button" Focusable="True" BorderThickness="1" Width="80" Height="33" VerticalAlignment="Top" >
</ToggleButton>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=tglButton, Path=IsChecked}" Value="true">
<Setter Property="Background" TargetName="RowHeaderBorder" Value ="Green"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here is the style of the DataGridRow:
<Style x:Key="DataGridRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="{StaticResource DataGridRowBorder}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="{StaticResource DataGridRowHoveredBackground}" />
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" BlurRadius="20"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="{StaticResource RowBackgroundSelectedBrush2}" />
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" BlurRadius="20"/>
</Setter.Value>
</Setter>
</Trigger>
<DataTrigger Binding="{Binding ElementName=DataGridRowHeader.tglButton, Path=IsChecked}" Value="true">
<Setter Property="Background" Value ="Green"/>
</DataTrigger>
</Style.Triggers>
</Style>
This is because tglButton is present in the row header, which is a child of the DataGridRow. A trigger defined in child row header is trying to update a property of the parent (DataGridRow) and is not able to find it.
One solution for this is to define the template for DataGridRowHeader inside the template for DataGridRow and supply a name for it, which can be used in the trigger. A very crude example:
<Style
TargetType="{x:Type DataGridRow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True"
CornerRadius="8,8,8,8">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</SelectiveScrollingGrid.ColumnDefinitions>
<SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</SelectiveScrollingGrid.RowDefinitions>
<DataGridCellsPresenter Grid.Column="1"
ItemsPanel="{TemplateBinding ItemsPanel}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<DataGridDetailsPresenter Grid.Column="1"
Grid.Row="1"
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen,
ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical},
Converter={x:Static DataGrid.RowDetailsScrollingConverter},
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
Visibility="{TemplateBinding DetailsVisibility}" />
<DataGridRowHeader Name="RHeader" Grid.RowSpan="2"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
Visibility="{Binding HeadersVisibility,
ConverterParameter={x:Static DataGridHeadersVisibility.Row},
Converter={x:Static DataGrid.HeadersVisibilityConverter},
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ToggleButton x:Name="tglButton"
Grid.Column="1"
Content="Button"
Focusable="True"
BorderThickness="1"
Width="80"
Height="33"
VerticalAlignment="Top">
</ToggleButton>
</Grid>
</DataGridRowHeader>
</SelectiveScrollingGrid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter TargetName="DGR_Border"
Property="Background"
Value="Gray" />
</Trigger>
<DataTrigger Binding="{Binding ElementName=tglButton, Path=IsChecked}"
Value="true">
<Setter Property="Background"
TargetName="RHeader"
Value="Green" />
<Setter Property="Background"
Value="Green" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="DataContext"
Value="{Binding RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"
Value="Aqua" />
<Style.Triggers>
<Trigger Property="IsSelected"
Value="true">
<Setter Property="Foreground"
Value="Black" />
<Setter Property="Background"
Value="Pink" />
<Setter Property="FontWeight"
Value="Bold" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0"
BlurRadius="20" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>

How to customize the WPF Ribbon 4.5 (styles, templates, etc.)

I try to customize System.Windows.Controls.Ribbon from the .Net Framework 4.5 so it can be used with the Expression Dark theme (dark colors like in default theme of the Blend).
I've tried following ideas, but until now without any progress:
change the Background of the ribbon: will change only the main
Color, but leaves all other glossy colors, highlight colos etc.
change the styles and templates: I couldn't find any default templates for the
Ribbon 4.5. I've tried to get them via Tools like ShowMeTheTemplate,
but it seems that they use some internal classes.
customizing the templates with Blend for VS2012: I get always an error "Copy Template failed."
use the .net 4 ribbon from the RibbonControlLibrary: the RibbonWindow
Looks ugly in the Windows 8 (see WPF RibbonWindow + Windows 8 -
control box looks bad), that I can't solve
Any help would be appreciated, all suggestions are welcome.
I was able to extract a fully working template using Show me the templates. To do that I modified it to extract templates from "System.Windows.Controls.Ribbon" (rather than the main framework assembly).
It gives me the following:
https://gist.github.com/drayde/75526b570a266f5f8f38 (too long to paste here)
Just add this to your resources and use it like this:
<Ribbon Template="{StaticResource ribbonTemplate}">
...
</Ribbon>
By modifying the template you should have full control over how your ribbon is displayed.
You can change a couple of colors by setting properties on the ribbon:
<ribbon:Ribbon x:Name="Ribbon"
Background="Khaki"
BorderBrush="Brown"
MouseOverBackground="LightCoral"
MouseOverBorderBrush="Coral"
PressedBackground="LightGreen"
PressedBorderBrush="Green"
CheckedBackground="LightBlue"
CheckedBorderBrush="Blue"
FocusedBackground="LightSlateGray"
FocusedBorderBrush="SlateBlue">
Not exactly a good-looking example, but shows how to do it.
Would be interested how to do a complete re-styling as well...
I followed this answer to get a template from VS.
It failed in a similar fashion as OP described.
Then I patched-in the missing parts {Binding (0)} using the gist from #Andreas.
To test, I set all the color properties to black in my view, and 50% magenta in the newly created template.
About this time I am ready to give up on System.Controls.Windows.Ribbon and try Fluent.Ribbon...
Template:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
xmlns:swcrp="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<!-- Template Colors -->
<SolidColorBrush x:Key="GroupsInnerBorderBrush" Color="#60FFFFFF"/>
<SolidColorBrush x:Key="QatTopHostBorderBrush1" Color="#66CCCCCC"/>
<SolidColorBrush x:Key="QatTopHostBorderBrush2" Color="#77222222"/>
<SolidColorBrush x:Key="QatTopHostBorderBrush3" Color="#81444444"/>
<SolidColorBrush x:Key="QatTopHostBorderBrush4" Color="#69EEEEEE"/>
<!-- #71000000 -->
<s:Byte x:Key="r">#00</s:Byte>
<s:Byte x:Key="g">#00</s:Byte>
<s:Byte x:Key="b">#00</s:Byte>
<s:Byte x:Key="a">#71</s:Byte>
<Color x:Key="DropShadowColor" R="{StaticResource r}" G="{StaticResource g}" B="{StaticResource b}" A="{StaticResource a}"/>
<LinearGradientBrush x:Key="GroupsBorderBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#EEFFFFFF" Offset="0"/>
<GradientStop Color="#BBFFFFFF" Offset="0.1"/>
<GradientStop Color="#05FFFFFF" Offset="0.5"/>
<GradientStop Color="#20FFFFFF" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="TitleBarBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#EEFFFFFF" Offset="0"/>
<GradientStop Color="#BBFFFFFF" Offset="0.1"/>
<GradientStop Color="#05FFFFFF" Offset="0.5"/>
<GradientStop Color="#20FFFFFF" Offset="1"/>
</LinearGradientBrush>
<!-- Template -->
<ControlTemplate x:Key="RibbonTemplate" TargetType="{x:Type Ribbon}">
<Grid SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border x:Name="BackgroundBorder" Grid.ColumnSpan="3" Grid.Row="1" Grid.RowSpan="3"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"/>
<Border Grid.ColumnSpan="3" Grid.Row="1">
<Popup x:Name="PART_ITEMSPRESENTERPOPUP" AllowsTransparency="True"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
<mwt:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" RenderOptions.ClearTypeHint="Enabled"
FocusVisualStyle="{x:Null}" Focusable="True" Margin="0,0,5,5">
<Border x:Name="CollapsedPopupBackgroundBorder" Background="{TemplateBinding Background}">
<ContentControl x:Name="popupItemsPresenterHost" KeyboardNavigation.DirectionalNavigation="Cycle"
Focusable="False" Margin="0,1,0,0" KeyboardNavigation.TabNavigation="Cycle"/>
</Border>
</mwt:SystemDropShadowChrome>
</Popup>
</Border>
<ContentControl x:Name="mainItemsPresenterHost" Grid.ColumnSpan="3" Focusable="False" Grid.Row="2">
<Border x:Name="groupsBorder" BorderThickness="1,0,1,1" Height="91" SnapsToDevicePixels="True"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{StaticResource GroupsBorderBackgroundBrush}">
<Border BorderThickness="0,0,0,1" Margin="0,0,0,1" SnapsToDevicePixels="True"
BorderBrush="{StaticResource GroupsInnerBorderBrush}">
<ItemsPresenter x:Name="ItemsPresenter"/>
</Border>
</Border>
</ContentControl>
<Border x:Name="QatBottomHost" Grid.ColumnSpan="3" Grid.Row="3" BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter x:Name="QatBottomHostContentPresenter" IsHitTestVisible="True"
HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
<Border x:Name="titleBarBackground" BorderThickness="0,0,0,1" Grid.ColumnSpan="3" Visibility="Collapsed"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{StaticResource TitleBarBackgroundBrush}"/>
<DockPanel Grid.ColumnSpan="3" Grid.Column="0" Height="22" LastChildFill="True">
<ContentControl x:Name="windowButtonPlaceHolder" DockPanel.Dock="Right" Focusable="False"
IsHitTestVisible="False" Margin="3,0,0,0" Width="35">
<ContentControl.Visibility>
<TemplateBinding Property="IsHostedInRibbonWindow">
<TemplateBindingExtension.Converter>
<BooleanToVisibilityConverter />
</TemplateBindingExtension.Converter>
</TemplateBinding>
</ContentControl.Visibility>
</ContentControl>
<ContentControl x:Name="windowIconPadding" DockPanel.Dock="Left" Focusable="False"
IsHitTestVisible="False" Margin="0,0,3,0" Width="16"/>
<swcrp:RibbonTitlePanel x:Name="PART_TitlePanel">
<Grid x:Name="QatTopHost">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border x:Name="QatTopHostLeftBorder" BorderBrush="{StaticResource QatTopHostBorderBrush1}"
BorderThickness="1,0,1,0.9" Background="{StaticResource QatTopHostBorderBrush2}" Grid.Column="0"
CornerRadius="0,0,2,2" Margin="8,2,0,2" Width="3"/>
<ContentPresenter x:Name="QatTopHostContentPresenter" Grid.Column="1" IsHitTestVisible="True"
Content="{TemplateBinding QuickAccessToolBar}"/>
<Border x:Name="QatTopHostRightBorder" BorderBrush="{StaticResource QatTopHostBorderBrush1}"
BorderThickness="1,0,1,0.9" Background="{StaticResource QatTopHostBorderBrush2}" Grid.Column="2"
CornerRadius="0,0,2,2" Margin="0,2,1,2" Width="3"/>
</Grid>
<ContentPresenter x:Name="PART_TitleHost" ContentTemplate="{TemplateBinding TitleTemplate}"
Content="{TemplateBinding Title}" ContentSource="Title"
TextElement.Foreground="{DynamicResource {x:Static SystemColors.ActiveCaptionTextBrushKey}}"
TextElement.FontWeight="{DynamicResource {x:Static SystemFonts.CaptionFontWeightKey}}"
TextElement.FontSize="{DynamicResource {x:Static SystemFonts.CaptionFontSizeKey}}"
TextElement.FontFamily="{DynamicResource {x:Static SystemFonts.CaptionFontFamilyKey}}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False" Margin="3,0" MinWidth="75" MinHeight="22">
<ContentPresenter.Resources>
<DataTemplate x:Key="{DataTemplateKey DataType={x:Type s:String}}" DataType="{x:Type s:String}">
<TextBlock x:Name="titleTextBlock" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Margin="0,-2,0,0" Text="{TemplateBinding Content}" TextTrimming="CharacterEllipsis"/>
<DataTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=(SystemParameters.IsGlassEnabled)}" Value="True"/>
<Condition Binding="{Binding IsHostedInRibbonWindow, RelativeSource={RelativeSource FindAncestor,
AncestorLevel=1, AncestorType={x:Type Ribbon}}}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Effect" TargetName="titleTextBlock">
<Setter.Value>
<DropShadowEffect BlurRadius="5" Color="White" ShadowDepth="0"/>
</Setter.Value>
</Setter>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=(SystemParameters.IsGlassEnabled)}" Value="False">
<Setter Property="Margin" TargetName="titleTextBlock" Value="0"/>
<Setter Property="VerticalAlignment" TargetName="titleTextBlock" Value="Center"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
<Setter Property="Margin" TargetName="titleTextBlock" Value="0,1,0,0"/>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=(SystemParameters.UxThemeName)}" Value="AeroLite"/>
<Condition Binding="{Binding Path=(SystemParameters.IsGlassEnabled)}" Value="False"/>
<Condition Binding="{Binding IsHostedInRibbonWindow, RelativeSource={RelativeSource FindAncestor,
AncestorLevel=1, AncestorType={x:Type Ribbon}}}" Value="True"/>
<Condition Binding="{Binding WindowState, RelativeSource={RelativeSource FindAncestor,
AncestorLevel=1, AncestorType={x:Type RibbonWindow}}}" Value="Normal"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" TargetName="titleTextBlock" Value="0,0,0,7"/>
</MultiDataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ContentPresenter.Resources>
</ContentPresenter>
<RibbonContextualTabGroupItemsControl x:Name="PART_ContextualTabGroupItemsControl"
HorizontalAlignment="Center" IsHitTestVisible="True"
WindowChrome.IsHitTestVisibleInChrome="True"/>
</swcrp:RibbonTitlePanel>
</DockPanel>
<ContentPresenter x:Name="applicationMenu" Content="{TemplateBinding ApplicationMenu}" Grid.Row="1" VerticalAlignment="Top"/>
<RibbonTabHeaderItemsControl x:Name="TabHeaderItemsControl" Grid.Column="1"
HorizontalAlignment="Left" Margin="1,1,1,0" Grid.Row="1" VerticalAlignment="Top"/>
<ContentPresenter x:Name="PART_HelpPane" ContentTemplate="{TemplateBinding HelpPaneContentTemplate}"
Content="{TemplateBinding HelpPaneContent}" Grid.Column="2" ContentSource="HelpPaneContent"
HorizontalAlignment="Right" Grid.Row="1" VerticalAlignment="Top"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsCollapsed" Value="True">
<Setter Property="Visibility" TargetName="applicationMenu" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="QatBottomHost" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="QatTopHost" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="mainItemsPresenterHost" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="TabHeaderItemsControl" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="PART_HelpPane" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="PART_ContextualTabGroupItemsControl" Value="Collapsed"/>
<Setter Property="MinWidth" TargetName="PART_TitleHost" Value="0"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsCollapsed" Value="True"/>
<Condition Property="IsHostedInRibbonWindow" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" Value="Collapsed"/>
</MultiTrigger>
<Trigger Property="ShowQuickAccessToolBarOnTop" Value="False">
<Setter Property="Content" TargetName="QatTopHostContentPresenter" Value="{x:Null}"/>
<Setter Property="Visibility" TargetName="QatTopHost" Value="Collapsed"/>
<Setter Property="Content" TargetName="QatBottomHostContentPresenter"
Value="{Binding QuickAccessToolBar, RelativeSource={RelativeSource TemplatedParent}}"/>
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0,0,0,1"/>
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding QuickAccessToolBar.HasItems, RelativeSource={RelativeSource Self}}" Value="False"/>
<Condition Binding="{Binding QuickAccessToolBar.CustomizeMenuButton, RelativeSource={RelativeSource Self}}" Value="{x:Null}"/>
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" TargetName="QatTopHost" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="QatBottomHost" Value="Collapsed"/>
</MultiDataTrigger>
<Trigger Property="IsMinimized" Value="True">
<Setter Property="Content" TargetName="mainItemsPresenterHost" Value="{x:Null}"/>
<Setter Property="Visibility" TargetName="mainItemsPresenterHost" Value="Collapsed"/>
<Setter Property="Content" TargetName="popupItemsPresenterHost" Value="{Binding ElementName=groupsBorder}"/>
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0,0,0,1"/>
</Trigger>
<Trigger Property="WindowIconVisibility" Value="Collapsed">
<Setter Property="Visibility" TargetName="windowIconPadding" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="QatTopHostLeftBorder" Value="Collapsed"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMinimized" Value="True"/>
<Condition Property="ShowQuickAccessToolBarOnTop" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="BorderThickness" TargetName="QatBottomHost" Value="0,1,0,0"/>
</MultiTrigger>
<Trigger Property="IsHostedInRibbonWindow" Value="False">
<Setter Property="Grid.Row" TargetName="BackgroundBorder" Value="0"/>
<Setter Property="Grid.RowSpan" TargetName="BackgroundBorder" Value="4"/>
<Setter Property="Visibility" TargetName="titleBarBackground" Value="Visible"/>
<Setter Property="Visibility" TargetName="windowIconPadding" Value="Collapsed"/>
<Setter Property="Visibility" TargetName="QatTopHostLeftBorder" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsDropDownOpen" Value="True">
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0"/>
</Trigger>
<Trigger Property="HasDropShadow" SourceName="PART_ITEMSPRESENTERPOPUP" Value="True">
<Setter Property="Color" TargetName="Shdw" Value="{StaticResource DropShadowColor}"/>
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsActive, RelativeSource={RelativeSource FindAncestor,
AncestorLevel=1, AncestorType={x:Type RibbonWindow}}}" Value="False"/>
<Condition Binding="{Binding Path=(SystemParameters.IsGlassEnabled)}" Value="False"/>
<Condition Binding="{Binding IsHostedInRibbonWindow, RelativeSource={RelativeSource Self}}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="TextElement.Foreground" TargetName="PART_TitleHost"
Value="{DynamicResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}"/>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=(SystemParameters.UxThemeName)}" Value="Aero">
<Setter Property="Margin" TargetName="QatTopHost" Value="0,-3,0,0"/>
<Setter Property="Margin" TargetName="QatTopHostLeftBorder" Value="3,3,0,5"/>
<Setter Property="Background" TargetName="QatTopHostLeftBorder" Value="{StaticResource QatTopHostBorderBrush3}"/>
<Setter Property="BorderBrush" TargetName="QatTopHostLeftBorder" Value="{StaticResource QatTopHostBorderBrush4}"/>
<Setter Property="Margin" TargetName="QatTopHostRightBorder" Value="0,3,1,5"/>
<Setter Property="Background" TargetName="QatTopHostRightBorder" Value="{StaticResource QatTopHostBorderBrush3}"/>
<Setter Property="BorderBrush" TargetName="QatTopHostRightBorder" Value="{StaticResource QatTopHostBorderBrush4}"/>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=(SystemParameters.UxThemeName)}" Value="Aero"/>
<Condition Binding="{Binding WindowState, RelativeSource={RelativeSource FindAncestor,
AncestorLevel=1, AncestorType={x:Type RibbonWindow}}}" Value="Maximized"/>
</MultiDataTrigger.Conditions>
<Setter Property="Margin" TargetName="QatTopHost" Value="0"/>
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>

Categories