WPF User Control Draw Border Conditionally - wpf

I am drawing a custom control with the following xaml. The control has property named Angle, to rotate the control. If the angle is 90 degree, i want to draw the border differently. How can I conditionally do that in xaml?
<local:BaseControl x:Class="WPFManualControls.Valve"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFManualControls" x:Name="ValveControl" Loaded="ValveControl_Loaded">
<local:BaseControl.Resources>
<local:ValveMenuEnableConverter x:Key="ValveMenuEnableConverter"/>
<local:PinVisibleConverter x:Key="PinVisibleConverter"/>
<local:UnknownPinVisibleConverter x:Key="UnknownPinVisibleConverter"/>
<local:MenuVisibleConverter x:Key="MenuVisibleConverter"/>
<LinearGradientBrush x:Key="MenuBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA2A5A7" Offset="0"/>
<GradientStop Color="#FFA2A5A7" Offset="1"/>
<GradientStop Color="#FFA2A5A7" Offset="0.502"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="MenuItemBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA1B3C5" Offset="0"/>
<GradientStop Color="#FFA1B3C5" Offset="1"/>
<GradientStop Color="#FFFEFEFE" Offset="0.534"/>
</LinearGradientBrush>
<Style TargetType="{x:Type MenuItem}">
<EventSetter Event="MenuItem.Click" Handler="OnValveMenuItemClick"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border x:Name="Border" Width="150" Height="30" Background="#FF222624" CornerRadius="5"
Margin="3" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Grid VerticalAlignment="Center">
<!-- The Grid is used to hold together columns for an Icon, Content, Glyph checkmark and Arrow to show the next level
Size sharing is used in Grid so that the Icon, Content, Arrow for each MenuItem align together -->
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="17" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup"/>
<ColumnDefinition Width="14"/>
</Grid.ColumnDefinitions>
<!-- ContentPresenter to show an Icon if needed -->
<ContentPresenter Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center"
ContentSource="Icon"/>
<!-- Glyph is a checkmark if needed for a checkable menu -->
<Grid Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center">
<Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/>
</Grid>
<!-- Content for the menu text etc -->
<ContentPresenter Grid.Column="1"
Margin="{TemplateBinding Padding}"
x:Name="HeaderHost" RecognizesAccessKey="True"
ContentSource="Header" />
<!-- Arrow drawn path which points to the next level of the menu -->
<Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center">
<Path x:Name="ArrowPanelPath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,0 L0,8 L4,4 z"/>
</Grid>
<!-- The Popup is the body of the menu which expands down or across depending on the level of the item -->
<Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right" x:Name="SubMenuPopup" Focusable="false" AllowsTransparency="true"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
VerticalOffset="-3">
<Grid x:Name="SubMenu" VerticalAlignment="Center">
<Border VerticalAlignment="Center" x:Name="SubMenuBorder" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/>
<!-- StackPanel holds children of the menu. This is set bu IsItemsHost=True -->
<StackPanel VerticalAlignment="Center" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
</Grid>
</Popup>
</Grid>
</Border>
<!-- These triggers re-configure the four arrangements of MenuItem to show different levels of menu via Role -->
<ControlTemplate.Triggers>
<!-- Role = TopLevelHeader : this is the root menu item in a menu; the Popup expands down -->
<Trigger Property="Role" Value="TopLevelHeader">
<Setter Property="Margin" Value="0,1,0,1"/>
<Setter Property="Padding" Value="6,3,6,3"/>
<Setter Property="Grid.IsSharedSizeScope" Value="true"/>
<Setter Property="Placement" Value="Bottom" TargetName="SubMenuPopup"/>
<Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
</Trigger>
<!-- Role = TopLevelItem : this is a child menu item from the top level without any child items-->
<Trigger Property="Role" Value="TopLevelItem">
<Setter Property="Margin" Value="0,1,0,1"/>
<Setter Property="Padding" Value="6,3,6,3"/>
<Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
</Trigger>
<!-- Role = SubMenuHeader : this is a child menu item which does not have children -->
<Trigger Property="Role" Value="SubmenuHeader">
<Setter Property="DockPanel.Dock" Value="Top"/>
<Setter Property="Padding" Value="0,2,0,2"/>
<Setter Property="Grid.IsSharedSizeScope" Value="true"/>
</Trigger>
<!-- Role = SubMenuItem : this is a child menu item which has children-->
<Trigger Property="Role" Value="SubmenuItem">
<Setter Property="DockPanel.Dock" Value="Top"/>
<Setter Property="Padding" Value="0,2,0,2"/>
<Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
</Trigger>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter Property="PopupAnimation" Value="None" TargetName="SubMenuPopup"/>
</Trigger>
<!-- If no Icon is present the we collapse the Icon Content -->
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
</Trigger>
<!-- The GlyphPanel contains the CheckMark -->
<Trigger Property="IsChecked" Value="true">
<Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel"/>
<Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
</Trigger>
<Trigger Property="AllowsTransparency" SourceName="SubMenuPopup" Value="true">
<Setter Property="Margin" Value="0,0,3,3" TargetName="SubMenu"/>
<Setter Property="SnapsToDevicePixels" Value="true" TargetName="SubMenu"/>
<Setter Property="BitmapEffect" Value="{DynamicResource PopupDropShadow}" TargetName="SubMenuBorder"/>
</Trigger>
<!-- Using the system colors for the Menu Highlight and IsEnabled-->
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" TargetName="Border"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="DarkGray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
<Style TargetType="{x:Type local:Valve}">
<EventSetter Event="MouseLeftButtonUp" Handler="onMouseLeftDown">
</EventSetter>
<!--width= 35 height = 30-->
<Setter Property="Width" Value="33"/>
<Setter Property="Height" Value="28"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu Visibility="{Binding IsReadOnly, Converter={StaticResource MenuVisibleConverter}}" Name="ValveMenu" Background="{StaticResource MenuBorderBrush}">
<MenuItem Header="Open" Tag="{Binding ValveOpenCmdValue}"
IsEnabled="{Binding ValveStatus, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ConverterParameter=Open,
Converter={StaticResource ValveMenuEnableConverter}}">
</MenuItem>
<MenuItem Header="Close" Tag="{Binding ValveCloseCmdValue}"
IsEnabled="{Binding Path=ValveStatus, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ConverterParameter=Close, Converter={StaticResource ValveMenuEnableConverter}}">
</MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="ValveType" Value="SimpleValve">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Valve}">
<Viewbox Stretch="None" >
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="White" Name="grid" RenderTransformOrigin="0.5,0.5" >
<Border Background="#FF338471" BorderBrush="Black" BorderThickness="0,0,1,0">
<Border Background="#FF338471" BorderBrush="Black" BorderThickness="0,0,0,1">
<Border Background="#FF338471" BorderBrush="White" BorderThickness="1,1,0,0">
<Path x:Name="path" StrokeThickness="0.5" Fill="{Binding StateBackground,ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" Margin="7,3,7,3"
Stretch="Fill" Stroke="#FF000000"
Data="M0.58299745,0.57220548 L0.5,35.822212 24.874998,17.947205 z M49.589987,35.749308 L49.826791,0.49999999 25.374882,18.072205 z" >
</Path>
</Border>
</Border>
</Border>
<Grid.RenderTransform>
<RotateTransform Angle="{Binding Angle, ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" />
<!--<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="{Binding Angle, ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" />
<TranslateTransform/>
</TransformGroup>-->
</Grid.RenderTransform>
</Grid>
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Angle" Value="90">
<Setter Property="Width" Value="33"/>
<Setter Property="Height" Value="28"/>
</Trigger>
<Trigger Property="ValveType" Value="ThrottleValve">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Valve}">
<Grid Background="#FF338471" >
<Viewbox>
<!--<Border Width="35" Height="35" Background="#FF338471" BorderBrush="Black" BorderThickness="1,1,1,1">
<Grid Margin="1" >
<Path Fill="Black" Stretch="Fill" Stroke="Black" Margin="0,5.577,0,3.242" Data="M15.75,3 L18.5,0.5 98.5,79.5 95.5,82.25 z M0.5,41.25 L0.5,44.5 119.25,44.75 119.25,41 z M6.25,40.75 L16.627914,20.841994 20.377999,23.466998 11.750134,40.75 z M9.9354524,17.376201 L24.944459,13.383842 27.511961,27.641038 z"/>
<Path Fill="{Binding Path=StateBackground, ElementName=ValveControl}" Stretch="Fill" Stroke="Black"
Margin="8.349,0,8,0" Data="M258.75,98.5 L323,98.75 301.75,119.25 300.5,172.73734 324.25,194.75 259.75,194.48734 280.75,173 280.75,120 z"/>
</Grid>
</Border>-->
<Border HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="60" Height="50" >
<Grid >
<Path Fill="Black" Stretch="Fill" Stroke="Black" Margin="0,5.577,0,3.242" Data="M15.75,3 L18.5,0.5 98.5,79.5 95.5,82.25 z M0.5,41.25 L0.5,44.5 119.25,44.75 119.25,41 z M6.25,40.75 L16.627914,20.841994 20.377999,23.466998 11.750134,40.75 z M9.9354524,17.376201 L24.944459,13.383842 27.511961,27.641038 z"/>
<Path Fill="{Binding Path=StateBackground, ElementName=ValveControl}" Stretch="Fill" Stroke="Black" Margin="12.349,0,14.22,0" Data="M258.75,98.5 L323,98.75 301.75,119.25 300.5,172.73734 324.25,194.75 259.75,194.48734 280.75,173 280.75,120 z"/>
</Grid>
</Border>
</Viewbox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="ValveType" Value="SlotValve">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Valve}">
<Viewbox Stretch="Fill">
<Grid >
<Rectangle Fill="{Binding Path=StateBackground, ElementName=ValveControl}" Stroke="Transparent" Width="20" Height="150"/>
</Grid>
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger><!--{Binding PumpBackground, ElementName=ValveControl}-->
<Trigger Property="ValveType" Value="PinValve">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Valve}">
<Viewbox>
<DockPanel LastChildFill="True" Height="20" Width="200" >
<Rectangle Fill="YellowGreen" Stroke="Black" DockPanel.Dock="Top" Height="7" Margin="30,0,30,0" Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}" />
<DockPanel DockPanel.Dock="Bottom" Height="7">
<Rectangle Fill="Black" Stroke="Black" DockPanel.Dock="Bottom" Height="7"/>
</DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,-10,0,-7" >
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black"
HorizontalAlignment="Left" Margin="30,0,0,0" VerticalAlignment="Top" Width="8" Height="18"/>
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black"
DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="0,0,30,0" VerticalAlignment="Top" Width="8" Height="18"/>
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource UnknownPinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black"
HorizontalAlignment="Left" Margin="30,0,0,0" VerticalAlignment="Bottom" Width="8" Height="8"/>
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource UnknownPinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black"
DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="0,0,30,0" VerticalAlignment="Bottom" Width="8" Height="8"/>
</DockPanel>
</DockPanel>
<!--<DockPanel LastChildFill="True" Height="20" Width="200" >
<Rectangle Fill="YellowGreen" Stroke="Black" DockPanel.Dock="Top" Height="7" Margin="30,0,30,0" Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}" />
<Rectangle Fill="Black" Stroke="Black" DockPanel.Dock="Bottom" Height="7"/>
<DockPanel DockPanel.Dock="Top" Margin="0,-10,0,-7" >
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black" HorizontalAlignment="Left" Margin="30,0,0,0" VerticalAlignment="Top" Width="8" Height="18"/>
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding StateBackground, ElementName=ValveControl}" Stroke="Black" HorizontalAlignment="Right" Margin="0,0,30,0" VerticalAlignment="Top" Width="8" Height="18"/>
</DockPanel>
</DockPanel>-->
</Viewbox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</local:BaseControl.Resources>
<!--<Grid Width="35" Height="30" Background="#FF338471">
<Path x:Name="path" Fill="{Binding ControlBackground,ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" Margin="5,2,5,2"
Stretch="Fill" Stroke="#FF000000"
Data="M0.58299745,0.57220548 L0.5,35.822212 24.874998,17.947205 z M49.589987,35.749308 L49.826791,0.49999999 25.374882,18.072205 z" />
</Grid>-->
<!--<Grid Name="LayoutRoot">
<Viewbox Stretch="Fill">
<Grid MouseDown="OnValveMouseDown" Width="50" Height="30" Background="#FF338471" >
<Path x:Name="path" Fill="{Binding ControlBackground,ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" Margin="0,3,10,0"
Stretch="Fill" Stroke="#FF000000"
Data="M0.58299745,0.57220548 L0.5,35.822212 24.874998,17.947205 z M49.589987,35.749308 L49.826791,0.49999999 25.374882,18.072205 z" VerticalAlignment="Top" HorizontalAlignment="Right" Height="24" Width="30" />
<Grid.ContextMenu>
<ContextMenu Name="ValveMenu"
Background="{StaticResource MenuBorderBrush}"
>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
</Viewbox>
</Grid>-->
<!--<local:BaseControl.RenderTransform>
<RotateTransform Angle="{Binding Angle, ElementName=ValveControl, UpdateSourceTrigger=PropertyChanged}" CenterX="25" CenterY="25"/>
</local:BaseControl.RenderTransform>-->
<!--<DockPanel LastChildFill="True" Height="20" Width="200" >
<Rectangle Fill="Black" Stroke="Black" DockPanel.Dock="Bottom" Height="7"/>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,-7" >
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding ControlBackground, ElementName=ValveControl}" Stroke="Black" HorizontalAlignment="Left" Margin="30,0,0,0" VerticalAlignment="Top" Width="5" Height="18"/>
<Rectangle Visibility="{Binding ValveStatus, ElementName=ValveControl, Converter={StaticResource PinVisibleConverter}}"
Fill="{Binding ControlBackground, ElementName=ValveControl}" Stroke="Black" HorizontalAlignment="Right" Margin="0,0,30,0" VerticalAlignment="Top" Width="5" Height="18"/>
</DockPanel>
</DockPanel>-->
</local:BaseControl>

You already have a Trigger defined for the Angle Property:
<Trigger Property="Angle" Value="90">
<Setter Property="Width" Value="33"/>
<Setter Property="Height" Value="28"/>
</Trigger>
It is just a matter of adding an additional Setter, which would modify an element inside the ControlTemplate:
<Trigger Property="Angle" Value="90">
<Setter Property="Width" Value="33"/>
<Setter Property="Height" Value="28"/>
<!-- This setter will affect the Path.Data property when Angle=90 -->
<Setter TargetName="path" Property="Data" Value="M1.5,Etc"/>
</Trigger>

Related

How to change the color of an Icon inserted using DrawingImage

I want to change the color of an icon on mouse hover. This icon is to be used in the root menu item. The code I am using is:
<Style x:Key="MenuIcon" TargetType="{x:Type MenuItem}">
<Setter Property="Template" Value="{StaticResource MenuItemControlTemplate1}"/>
<Setter Property="Icon">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Geometry="M6 36v-3h36v3Zm0-10.5v-3h36v3ZM6 15v-3h36v3Z"
Brush="Red"/>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</Style>
I want to change the color of Brush from Red to White on mouse hover. How to achieve this?
MenuItemControlTemplate1 used in the above style is as follows:
<ControlTemplate x:Key="MenuItemControlTemplate1" TargetType="{x:Type MenuItem}">
<Border x:Name="templateRoot"
BorderBrush="#535353"
CornerRadius="3"
BorderThickness="1"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{TemplateBinding Icon}"/>
<ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Bottom" HorizontalOffset="-2">
<Border x:Name="SubMenuBorder" BorderBrush="#595959" BorderThickness="1" Background="#3A3A3A" Padding="2">
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
</Trigger>
<Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="MenuIcon" TargetType="{x:Type MenuItem}">
<Setter Property="Icon">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Geometry="M6 36v-3h36v3Zm0-10.5v-3h36v3ZM6 15v-3h36v3Z" Brush="Red"/>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}, Path=IsMouseOver}" Value="True">
<Setter Property="Icon">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Geometry="M6 36v-3h36v3Zm0-10.5v-3h36v3ZM6 15v-3h36v3Z" Brush="White"/>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
Instead of TargetType="{x:Type MenuItem}"
You need to put the parent of the MenuItem.
For example, if your situation is like this:
<Grid>
<MenuItem Style="{StaticResource MenuIcon}"/>
</Grid>
So do this:
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=IsMouseOver}" Value="True">
<Setter Property="Icon">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Geometry="M6 36v-3h36v3Zm0-10.5v-3h36v3ZM6 15v-3h36v3Z" Brush="White"/>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>

XAML code without resources and templates possible?

I found an example (the first one) for a slider,
which defines also a track with thumb.
Is it possible to recode it without resources and templates?
Thank you for your comments.
Erhy
I have done it.
Here the XAML code without template and style references
for the slider with track and thumb
<Slider x:Name="slidExample"
VerticalAlignment="Center" TickFrequency="37.5"
Minimum="0" Maximum="600" Value="500" Width="300" Margin="50,0,50,0"
SnapsToDevicePixels="true"
OverridesDefaultStyle="true"
IsTabStop="false"
Focusable="false"
>
<Slider.Style>
<Style TargetType="Slider">
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="MinHeight" Value="21" />
<Setter Property="MinWidth" Value="104" />
</Trigger>
</Style.Triggers>
</Style>
</Slider.Style>
<Slider.Template>
<ControlTemplate>
<Grid x:Name="GridOfslidExample">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TickBar x:Name="TopTickOfslidExample" Fill="LightGray" VerticalAlignment="Top"
SnapsToDevicePixels="True" Grid.Row="0" Placement="Top" Height="5"
Visibility="Visible">
</TickBar>
<Border BorderBrush="LightGray" BorderThickness="0,0,0,1" ></Border>
<Border x:Name="TrackBackground" VerticalAlignment="Center" Margin="0,-10,0,0" BorderBrush="Red" Background="Red" Height="3" Grid.Row="1" BorderThickness="1"/>
<Track Grid.Row="1" x:Name="PART_Track" Margin="0,-10,0,0" >
<Track.DecreaseRepeatButton>
<RepeatButton Command="Slider.DecreaseLarge" >
<RepeatButton.Style>
<Style TargetType="RepeatButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border SnapsToDevicePixels="True" Background="YellowGreen" BorderThickness="1" BorderBrush="YellowGreen" Height="3"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</RepeatButton.Style>
</RepeatButton>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="ThumbOfslidExample">
<Thumb.Style>
<Style TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<StackPanel Orientation="Vertical">
<Path Data="M 0 0 L 8 0 L 4 6 Z" Stroke="YellowGreen" Margin="-2,0,0,0" StrokeThickness="2" Fill="YellowGreen"></Path>
<Line X1="0" Y1="0" X2="0" Y2="7" Stroke="Gray" StrokeThickness="1" Margin="2,0,0,0" StrokeDashArray="1.5,1.5"></Line>
<TextBlock Foreground="Black" Margin="-2,30,0,0" Text="{Binding Value, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Slider}}}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Thumb.Style>
</Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="Slider.IncreaseLarge" >
<RepeatButton.Style>
<Style TargetType="RepeatButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Background="Transparent"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</RepeatButton.Style>
</RepeatButton>
</Track.IncreaseRepeatButton>
</Track>
<TextBlock Text="0" Grid.Row="1" Margin="0,15,0,0"></TextBlock>
<TickBar x:Name="BottomTickOfslidExample" Fill="LightGray" SnapsToDevicePixels="True" Grid.Row="2" Placement="Bottom" Height="4" Visibility="Collapsed" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Slider.TickPlacement" Value="TopLeft">
<Setter TargetName="TopTickOfslidExample" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="Slider.TickPlacement" Value="BottomRight">
<Setter TargetName="BottomTickOfslidExample" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="Slider.TickPlacement" Value="Both">
<Setter TargetName="TopTickOfslidExample" Property="Visibility" Value="Visible" />
<Setter TargetName="BottomTickOfslidExample" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Slider.Template>
</Slider>
I think I have fixed it.
The reason of missings commands of RepeatButton was the textfield in thumb.
Its name in the new source is "DisplaysValueInThumb".
I had to add a converter, because the value of the slider produce many decimal places, which hide the touch area of the repeat button.
Because I was unable to format the source correctly
you find the source here.
Erhy

TabControl TabItems Boarder color in WPF

I have following XAML Code that renders following TabControl
<UserControl x:Class="WpfControlLibrary1.UserControl1"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
xmlns:Microsoft_Windows_Themes="clr-
namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
Height="423" Width="639" MinHeight="300" MinWidth="500"
MaxHeight="470" MaxWidth="673"
xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map">
<UserControl.Resources>
<SolidColorBrush x:Key="OutlookButtonForeground" Color="White" >
</SolidColorBrush>
<LinearGradientBrush x:Key="OutlookButtonBackground" EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#0264AD" Offset="0"/>
<GradientStop Color="#0264AD" Offset="0.445"/>
<GradientStop Color="#0264AD" Offset="1"/>
<GradientStop Color="#0264AD" Offset="0.53"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="OutlookButtonHighlight" EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#03538E" Offset="0"/>
<GradientStop Color="#03538E" Offset="0.0967"/>
<GradientStop Color="#03538E" Offset="0.2580"/>
<GradientStop Color="#03538E" Offset="0.3870"/>
<GradientStop Color="#03538E" Offset="0.9677"/>
<GradientStop Color="#03538E" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="OutlookTabControlStyle" TargetType="{x:Type TabControl}">
<Setter Property="Foreground"
Value="{DynamicResource OutlookButtonForeground}"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="White"/>
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="MinWidth" Value="10"/>
<Setter Property="MinHeight" Value="10"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid ClipToBounds="true" SnapsToDevicePixels="true"
KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0"
Height="Auto"/>
<RowDefinition x:Name="RowDefinition1"
Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1"
Width="0"/>
</Grid.ColumnDefinitions>
<Grid x:Name="ContentPanel" Grid.Column="0"
Grid.Row="1"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2"
KeyboardNavigation.TabNavigation="Local">
<Microsoft_Windows_Themes:ClassicBorderDecorator
Background="White"
BorderBrush="White"
BorderStyle="Raised"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter SnapsToDevicePixels=
"{TemplateBinding SnapsToDevicePixels}"
Margin="2,2,2,2"
x:Name="PART_SelectedContentHost"
ContentSource="SelectedContent"/>
</Microsoft_Windows_Themes:ClassicBorderDecorator>
</Grid>
<StackPanel HorizontalAlignment="Stretch"
Margin="0,-2,0,0"
x:Name="HeaderPanel" VerticalAlignment="Top" Width="Auto"
Height="Auto" Grid.Row="1" IsItemsHost="True"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabStripPlacement"
Value="Bottom">
<Setter Property="Grid.Row"
TargetName="ContentPanel" Value="0"/>
<Setter Property="Height"
TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height"
TargetName="RowDefinition1" Value="Auto"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Left">
<Setter Property="Grid.Row"
TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column"
TargetName="ContentPanel" Value="1"/>
<Setter Property="Width"
TargetName="ColumnDefinition0" Value="Auto"/>
<Setter Property="Width"
TargetName="ColumnDefinition1" Value="*"/>
<Setter Property="Height"
TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height"
TargetName="RowDefinition1" Value="0"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter Property="Grid.Row"
TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column"
TargetName="ContentPanel" Value="0"/>
<Setter Property="Width"
TargetName="ColumnDefinition0" Value="*"/>
<Setter Property="Width"
TargetName="ColumnDefinition1" Value="Auto"/>
<Setter Property="Height"
TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height"
TargetName="RowDefinition1" Value="0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground"
Value="{DynamicResource
{x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="OutlookTabItemStyle" TargetType="{x:Type TabItem}">
<!--BorderBrush="#FF6593CF"-->
<Setter Property="Padding" Value="12,2,12,2"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static
SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static
SystemColors.ControlBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border SnapsToDevicePixels="true" x:Name="shadow"
Background="{TemplateBinding Background}"
BorderThickness="0.5" >
<ContentPresenter SnapsToDevicePixels= "
{TemplateBinding SnapsToDevicePixels}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{Binding
Path=VerticalContentAlignment,
RelativeSource={RelativeSource AncestorType={x:Type
ItemsControl}}}" ContentSource="Header" RecognizesAccessKey="True"
HorizontalAlignment="Left" />
<Border.BorderBrush>
<SolidColorBrush Color="White">
</SolidColorBrush>
</Border.BorderBrush>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Selector.IsSelected"
Value="True">
<!--<Setter Property="Background"
TargetName="shadow" Value="{DynamicResource
OutlookButtonHighlight}"/>-->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Height="420" Width="664">
<TabControl Name="RouteProcessingTabControl" VerticalAlignment="Stretch"
Width="200" Height="Auto" TabStripPlacement="Top" Style="
{DynamicResource OutlookTabControlStyle}" HorizontalAlignment="Left">
<TabItem Height="60" Style="{DynamicResource
OutlookTabItemStyle}" Background="{DynamicResource
OutlookButtonBackground}" Foreground="{DynamicResource
OutlookButtonForeground}">
<Grid DataContext="{Binding}" />
<TabItem.Header>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0">
<Image Height="25"
Source="Image\RoutingPreferences.png"></Image>
<TextBlock Text="Routing Preferences" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}" Foreground="
{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0">
<Image Height="20"
Source="Image\HazardousMaterialsRestrictions.png"></Image>
<TextBlock Text="Hazardous Materials Restrictions"
Width="160" TextWrapping="Wrap" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}"
Foreground="{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="20" Source="Image\DisplayOption.png">
</Image>
<TextBlock Text="Display Option" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}"
Foreground="{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="20" Source="Image\RoutingCostInputs.png">
</Image>
<TextBlock Text="Routing Cost Inputs" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}"
Foreground="{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="20" Source="Image\RoadWork.png"></Image>
<TextBlock Text="RoadWork" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}"
Foreground="{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="20"
Source="Image\TruckConfiguration.png"></Image>
<TextBlock Text="Truck Configuration" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Height="60" Style="{DynamicResource OutlookTabItemStyle}"
Background="{DynamicResource OutlookButtonBackground}"
Foreground="{DynamicResource OutlookButtonForeground}">
<Grid/>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="20" Source="Image\Tolls.png"></Image>
<TextBlock Text="Tolls" Margin="2,0,0,0"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontWeight="Bold" FontSize="13" />
</StackPanel>
</TabItem.Header>
</TabItem>
</TabControl>
</Grid>
</UserControl>
Even I have Boarder Color White, its generating Slightly Sky Blue boarder color, this is not I want, I want White and Thin Boarder like below Picture! Can anyone suggest solution here? Thank you!
This looks like a Layout Rounding issue. Try changing your <Border> in the Template of the OutlookTabItemStyle style to:
<Border
x:Name="shadow"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
Background="{TemplateBinding Background}"
BorderThickness="1"
>

WPF - Custom Tab Control Binding

I'm creating a custom tab control and the tabs were working fine, but when I click a button in my toolbar, the selected tab disappears.
How do I get the selected tab to remain Visible until the next tab is selected?
How do I bind the Visibility of the selected tab with the Visibility of it's corresponding toolbar and DataGrid? (Example: If I click on Tab2, I want Tab2Tools and dgTab2 to become Visible, and all other TabTools and DataGrids to be Hidden or Collapsed.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Color x:Key="TabGradientTop">#FFFFFFFF</Color>
<Color x:Key="TabGradientBottom">#FFC0CBE8</Color>
<SolidColorBrush x:Key="TabBarText" Color="#FF353C66"/>
<SolidColorBrush x:Key="TabBarTop" Color="#FFFFFFFF"/>
<SolidColorBrush x:Key="TabBarBottom" Color="#FFC0CBE8"/>
<SolidColorBrush x:Key="TabBarBorder" Color="#FF8E96AC"/>
<SolidColorBrush x:Key="TabMou5eOverColor" Color="#FFFFB700"/>
<Style x:Key="TabStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="{DynamicResource TabBarText}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="TabNormal" Fill="Transparent"/>
<Rectangle x:Name="TabMou5eOver" Fill="{StaticResource TabBarBottom}" Height="30" Stroke="{StaticResource TabMou5eOverColor}" StrokeThickness="1" RadiusY="4" RadiusX="4" Visibility="Hidden" />
<Rectangle x:Name="TabMou5eOver2" Fill="{StaticResource TabBarBorder}" Height="1" VerticalAlignment="Bottom" Visibility="Hidden" />
<Rectangle x:Name="TabMou5ePressed" Fill="{StaticResource TabBarTop}" Height="30" Stroke="{StaticResource TabBarBorder}" RadiusY="4" RadiusX="4" Visibility="Hidden" />
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Visibility" TargetName="TabMou5eOver2" Value="Visible"/>
<Setter Property="Visibility" TargetName="TabMou5eOver" Value="Visible"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Visibility" TargetName="TabMou5ePressed" Value="Visible"/>
</Trigger>
<Trigger Property="IsDefaulted" Value="True">
<Setter Property="Visibility" TargetName="TabMou5ePressed" Value="Visible"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Visibility" TargetName="TabMou5ePressed" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="InvisiStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="{DynamicResource TabBarText}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<!--Gadients-->
<StackPanel Orientation="Vertical">
<Rectangle Height="46">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource TabGradientBottom}" Offset="0.25"/>
<GradientStop Color="{StaticResource TabGradientTop}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="1" Fill="{StaticResource TabBarBorder}"/>
<Rectangle Height="87">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource TabGradientBottom}" Offset="0.45" />
<GradientStop Color="{StaticResource TabGradientTop}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="1" Fill="{StaticResource TabBarBottom}" Opacity="0.5"/>
<Rectangle Height="1" Fill="{StaticResource TabBarBottom}"/>
<Rectangle Height="1" Fill="{StaticResource TabBarBorder}"/>
</StackPanel>
<!--Tabs-->
<Grid Margin="15,22,0,0">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Button x:Name="cmdTab1" Content="Tab1" Style="{DynamicResource TabStyle}" Width="55" Height="25" Margin="10,0,0,0" IsDefault="True"/>
<Button x:Name="cmdTab2" Content="Tab2" Style="{DynamicResource TabStyle}" Width="55" Height="25" Margin="10,0,0,0" />
<Button x:Name="cmdTab3" Content="Tab3" Style="{DynamicResource TabStyle}" Width="55" Height="25" Margin="10,0,0,0" />
<Button x:Name="cmdTab4" Content="Tab4" Style="{DynamicResource TabStyle}" Width="55" Height="25" Margin="10,0,0,0" />
</StackPanel>
</Grid>
<!--Tool Bars-->
<StackPanel x:Name="Tab1Tools" Orientation="Horizontal" Margin="10,52,0,0" Height="80" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<Button x:Name="Tab1Login" Content="Login" Height="18" Margin="5,0,0,0" Style="{DynamicResource InvisiStyle}"/>
<Button x:Name="Tab1Request" Content="Request Password" Height="18" Margin="5,0,0,0" Style="{DynamicResource InvisiStyle}"/>
<Rectangle Fill="{StaticResource TabBarBorder}" Height="1" Margin="5,5,5,0"/>
<Rectangle Fill="{StaticResource TabBarTop}" Height="1" Margin="5,0,5,5" Opacity="0.5"/>
<Button x:Name="Tab1Exit" Content="Exit" Height="18" Margin="5,0,0,0" Style="{DynamicResource InvisiStyle}"/>
</StackPanel>
</StackPanel>
<StackPanel x:Name="Tab2Tools" Orientation="Horizontal" Margin="10,52,0,0" Height="80" VerticalAlignment="Top" Visibility="Hidden" />
<StackPanel x:Name="Tab3Tools" Orientation="Horizontal" Margin="10,52,0,0" Height="80" VerticalAlignment="Top" Visibility="Hidden" />
<StackPanel x:Name="Tab4Tools" Orientation="Horizontal" Margin="10,52,0,0" Height="80" VerticalAlignment="Top" Visibility="Hidden" />
<!--Data Grids-->
<DataGrid x:Name="dgTab2" ItemsSource="{Binding}" Margin="0,137,0,0" AutoGenerateColumns="True" Visibility="Collapsed" />
<DataGrid x:Name="dgTab3" ItemsSource="{Binding}" Margin="0,137,0,0" AutoGenerateColumns="True" Visibility="Collapsed" />
<DataGrid x:Name="dgTab4" ItemsSource="{Binding}" Margin="0,137,0,0" AutoGenerateColumns="True" Visibility="Collapsed" />
</Grid>
</Window>
You can bind the button click using Command property in your viewmodel and define a method using delegates. In your method you can set the visibility of datagrids as per the requirement.
Regarding your first query, I simply copied your code on my local and tried executing it, I do not see any tabs becoming invisible while the other one is selected.

Styling MenuItem not working as expected

I have a menu.
Here is the xaml for creating this menu :
<Menu Grid.Column="0" ItemsSource="{Binding ParentButtons}" >
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<Menu.Resources>
<Style TargetType="{x:Type MenuItem}">
<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 VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<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"/>
<Path x:Name="GlyphPanel" 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="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="3" Visibility="Collapsed" VerticalAlignment="Center"/>
<ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="1" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right">
<Border x:Name="SubMenuBorder" BorderBrush="#FF999999" BorderThickness="1" Background="#FFF0F0F0" Padding="2">
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
</Canvas>
<!--<Rectangle Fill="#FFD7D7D7" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>-->
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
</Trigger>
<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="GlyphPanel" Value="#FF707070"/>
</Trigger>
<Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Menu.Resources>
<Menu.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type model:Design_Master_Buttons}"
ItemsSource="{Binding Design_Master_Buttons1}">
<StackPanel Orientation="Horizontal">
<Path Data="{Binding ImageData}"
Stretch="Uniform" Width="32" Height="32" Margin="5" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
<Path.Resources>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="#FFFFFFFF" />
<Style.Triggers>
<Trigger Property="MenuItem.IsMouseOver" Value="True">
<Setter Property="Fill" Value="{Binding MouseOverColor}" />
</Trigger>
</Style.Triggers>
</Style>
</Path.Resources>
</Path>
<TextBlock Text="{Binding Title}" VerticalAlignment="Center">
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="Margin" Value="10,0,0,0" />
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Margin" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Resources>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</Menu.ItemTemplate>
</Menu>
But I have got 1 problem:
When I mouseOver Path (It's working good):
When I mouseOver MenuItem (It's not working as expected) :
Try this : In my case stackpanel as AncestorType is not worked so i used Menuitem.
<StackPanel>
<Path x:Name="PathData" Data="M 0 0 L 0 5 L 5 5 Z" Stretch="Uniform" Width="32" Height="32" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0"/>
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
<Path.Style>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="Transparent" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type MenuItem}},Path=IsMouseOver}" Value="True">
<Setter Property="Fill" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</StackPanel>
Your Path resource is not correct replace it by :
<Path.Resources>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="#FFFFFFFF" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=StackPanel,AncestorLevel=1}, Path=IsMouseOver}" Value="True" >
<Setter Property="Fill" Value="{Binding MouseOverColor}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Resources>
And add Background="#01000000" to the StackPanel, it will be able to detect IsMouseOver property.
And now it will works.
Regards.

Resources