I am creating a button style. Paste this into a window to see the idea:
<Style x:Key="SelectionButton3"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="False">
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="TheBorder"
BorderThickness="0,1.5,1.5,1.5"
CornerRadius="3"
Background="SteelBlue"
Height="35"
Grid.Column="1"
Grid.Row="0"
Margin="-31"
BorderBrush="DarkSlateBlue">
<Border.BitmapEffect>
<DropShadowBitmapEffect x:Name="BorderShadow"
ShadowDepth="0"/>
</Border.BitmapEffect>
</Border>
<Rectangle Fill="SteelBlue"
Stroke="DarkSlateBlue"
Grid.Row="0"
Grid.Column="0">
<Rectangle.LayoutTransform>
<RotateTransform Angle="-45" />
</Rectangle.LayoutTransform>
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect ShadowDepth="5"/>
</Rectangle.BitmapEffect>
</Rectangle>
<ContentPresenter x:Name="ContentArea"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground"
Value="LightGray" />
<Setter Property="FontFamily"
Value="Segoe UI" />
</Style>
<Button Click="Button_Click"
Style="{StaticResource SelectionButton3}"
Width="185">
</Button>
What I would like to have happen is for the Borders drop shadow to appear when the mouse is over either the Border or the Rectangle. I know I need a trigger, but I'm not really sure where & how to do it.
Can someone point me in the right direction?
Thanks
<Style x:Key="SelectionButton3"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="False">
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="TheBorder"
BorderThickness="0,1.5,1.5,1.5"
CornerRadius="3"
Background="SteelBlue"
Height="35"
Grid.Column="1"
Grid.Row="0"
Margin="-31"
BorderBrush="DarkSlateBlue">
</Border>
<Rectangle Name="rect" Fill="SteelBlue"
Stroke="DarkSlateBlue"
Grid.Row="0"
Grid.Column="0">
<Rectangle.LayoutTransform>
<RotateTransform Angle="-45" />
</Rectangle.LayoutTransform>
</Rectangle>
<ContentPresenter x:Name="ContentArea"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="TheBorder" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="0" />
</Setter.Value>
</Setter>
<Setter TargetName="rect" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect ShadowDepth="5"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground"
Value="LightGray" />
<Setter Property="FontFamily"
Value="Segoe UI" />
</Style>
Note that unless you're using .NET 3.0 or 3.5 pre SP1, you should use Effect instead of BitmapEffect. The BitmapEffect property has been deprecated in 3.5 SP1
Related
Application with an Dashboard.
The Dashboard uses Cards in the form of User Controls. These Controls weren't responsive so I put them into Viewboxes. Some Cards are working but some don't. Especially the Cards with DataGrids in them don't work for me. Maybe you can help me out.
DashboardView
Here is the DashboardPage:
<Page x:Class="Keppler.MES.Common.Pages.Dashboard"
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"
xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:local="clr-namespace:Keppler.MES.Common.Pages"
xmlns:pageviewmodels="clr-namespace:Keppler.ViewModels.PageViewModels;assembly=Keppler.ViewModels" xmlns:controls="clr-namespace:Keppler.MES.Common.Pages.Controls"
mc:Ignorable="d"
Title="DashboardPage">
<Page.DataContext>
<pageviewmodels:VMDashboard/>
</Page.DataContext>
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Common\ResourceDictionaries\KepplerColorsAndBrushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<controls:KepplerEffortCard PageName="Bookings" GroupedEfforts="{Binding EffortOfLastWorkDay}" EffortOfBindings="{Binding LastWorkDaysEffort}" JumpToLink="{Binding RequestPageChangeCommand}" Grid.Row="3" Grid.ColumnSpan="6" Grid.RowSpan="2"/>
<controls:KepplerEffortCard PageName="Bookings" GroupedEfforts="{Binding EffortOfLastWeek}" EffortOfBindings="{Binding LastWeeksEffort}" JumpToLink="{Binding RequestPageChangeCommand}" Grid.Column="6" Grid.Row="3" Grid.ColumnSpan="6" Grid.RowSpan="2"/>
<controls:KepplerOrdersCard PageName="Orders" Grid.ColumnSpan="12" Grid.Row="5" Grid.RowSpan="2" OrderBudgets="{Binding OrderBudgets}" JumpToLink="{Binding RequestPageChangeCommand}"/>
<controls:KepplerTurnOverCard Grid.Row="0" Grid.ColumnSpan="2" Header="{Binding TurnOverThisYear.Header}" TurnOver="{Binding TurnOverThisYear.TurnOver}" Grid.Column="0" Margin="10,0" />
<controls:KepplerTurnOverCard Grid.Row="0" Header="{Binding TurnOverLastYear.Header}" TurnOver="{Binding TurnOverLastYear.TurnOver}" Grid.Column="2" Grid.ColumnSpan="2" Margin="10,0" RenderTransformOrigin="0.5,0.5"/>
<controls:KepplerTurnOverCard Grid.Row="0" Grid.ColumnSpan="2" Header="{Binding TurnOverThisQuarter.Header}" TurnOver="{Binding TurnOverThisQuarter.TurnOver}" Grid.Column="4" Margin="10,0"/>
<controls:KepplerTurnOverCard Header="{Binding TurnOverThisMonth.Header}" TurnOver="{Binding TurnOverThisMonth.TurnOver}" Grid.ColumnSpan="2" Grid.Column="6" Grid.Row="0" Margin="10,0"/>
<Viewbox Grid.Row="1" Grid.Column="0" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding BudgetWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="2" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Invoices" WarningsInfo="{Binding InvoiceWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="4" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding ResourceWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="6" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding DeliveryWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="8" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerWarningCard PageName="Orders" WarningsInfo="{Binding WorkloadWarning}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="10" StretchDirection="Both" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
<controls:KepplerBankingCard BankingsInfo="{Binding BankingsInfo}"/>
</Viewbox>
<controls:KepplerCustomerCard PageName="Customers" Grid.Row="7" Grid.RowSpan="2" Customers="{Binding Customers}" Grid.ColumnSpan="12" JumpToLink="{Binding RequestPageChangeCommand}"/>
<controls:KepplerProjectsCard PageName="Projects" Grid.ColumnSpan="12" Grid.Row="9" Grid.RowSpan="2" Projects="{Binding Projects}" JumpToLink="{Binding RequestPageChangeCommand}"/>
</Grid>
Here is the Control:
<UserControl x:Class="Keppler.MES.Common.Pages.Controls.KepplerOrdersCard"
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"
xmlns:local="clr-namespace:Keppler.MES.Common.Pages.Controls"
mc:Ignorable="d"
Name="OrderBudgetCard"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\..\Common\ResourceDictionaries\KepplerColorsAndBrushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border CornerRadius="5" Margin="5" BorderThickness="0">
<Border.BitmapEffect>
<DropShadowBitmapEffect/>
</Border.BitmapEffect>
<Grid>
<Border x:Name="DBRounded" CornerRadius="5" BorderThickness="1" Background="#FF888888"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Border x:Name="Header" Grid.ColumnSpan="1" Grid.RowSpan="1" CornerRadius="5,5,0,0" BorderThickness="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFAE00" Offset="0"/>
<GradientStop Color="#FFFFC500" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Button Background="Transparent" Command="{Binding ElementName=OrderBudgetCard, Path=JumpToLink}" CommandParameter="{Binding ElementName=OrderBudgetCard, Path=PageName}" Grid.ColumnSpan="1" Grid.RowSpan="2">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"
BorderThickness="1" CornerRadius="5">
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FFFFAE00"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<DataGrid x:Name="dgOrderBudgets"
Background="Transparent"
ItemsSource="{Binding ElementName=OrderBudgetCard, Path=OrderBudgets}"
AutoGenerateColumns="False"
HorizontalGridLinesBrush="Transparent"
VerticalGridLinesBrush="Transparent"
BorderBrush="Transparent"
IsReadOnly="True" Grid.RowSpan="2">
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader">
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="auto"/>
<Setter Property="Margin" Value="5"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="black"/>
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="darkred"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="order number" Width="200" Binding="{Binding Order.Number}"/>
<DataGridTextColumn Header="budget [€]" Width="120" Binding="{Binding Order.Subtotal,StringFormat=C2, ConverterCulture=de-DE}"/>
<DataGridTextColumn Header="consumed [€]" Width="*" Binding="{Binding EffortInCash,StringFormat=C2, ConverterCulture=de-DE}"/>
<DataGridTextColumn Header="state" Width="*" Binding="{Binding Order.Title}"/>
</DataGrid.Columns>
</DataGrid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=DBRounded}"/>
</Grid.OpacityMask>
</Grid>
</Grid>
</Border>
I tried putting the other Controls into Viewboxes like the Warningcards, but I didnt get anything out of it. Doesnt matter if I used fill, uniform or uniformtofill.
I've been looking inside templates but can't find anything.
example
My XAML so far:
<TabControl HorizontalAlignment="Left" Height="285" BorderThickness="0" Margin="10,56,0,0" VerticalAlignment="Top" Width="495">
<TabItem Header="Main" Foreground="#38acfc" BorderThickness="0" Background="#0c142c" FontFamily="Myriad Pro Cond" FontSize="14" Style="{DynamicResource CustomTabControl}">
<Grid Background="#0c142c"/>
</TabItem>
</TabControl>
Use this ControlTemplate :
<Style TargetType="{x:Type TabControl}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TabPanel
Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
Margin="0,0,4,-1"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent" />
<Border
Name="Border"
Grid.Row="1"
Background="White"
BorderBrush="Transparent"
BorderThickness="1"
CornerRadius="2"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2" >
<ContentPresenter
Name="PART_SelectedContentHost"
Margin="0"
ContentSource="SelectedContent" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Gray" />
<Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This is my Style:
<Style TargetType="{x:Type Menu}" x:Key="StandardMenu">
<Style.Resources>
<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="Separator">
<Setter Property="Height" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Separator">
<Border BorderBrush="{StaticResource MenuSeparatorBorderBrush}" BorderThickness="1" Margin="25,0,0,0"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Foreground" Value="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}"/>
<Setter Property="FontSize" Value="{DynamicResource ApplicationFontSize}"/>
<Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<!--Border 1-->
<Border x:Name="Border" Background="Transparent" BorderBrush="Transparent" CornerRadius="2" BorderThickness="1" SnapsToDevicePixels="False">
<Grid x:Name="Grid">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="Col0" MinWidth="17" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="MenuTextColumnGroup"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup"/>
<ColumnDefinition x:Name="Col3" Width="14"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon"/>
<ContentPresenter Grid.Column="1" Margin="{TemplateBinding Padding}" x:Name="HeaderHost" RecognizesAccessKey="True" ContentSource="Header" VerticalAlignment="Center"/>
<ContentPresenter Grid.Column="2" Margin="8,1,8,1" x:Name="IGTHost" ContentSource="InputGestureText" VerticalAlignment="Center"/>
<Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center">
<Path x:Name="ArrowPanelPath" HorizontalAlignment="Right" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,0 L0,8 L4,4 z"/>
</Grid>
<Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right"
HorizontalOffset="-1"
x:Name="SubMenuPopup"
Focusable="false"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
AllowsTransparency="True">
<Grid Margin="0,0,5,5">
<!--Border 2-->
<Border x:Name="SubMenuBorder" CornerRadius="5"
BorderBrush="{StaticResource MenuSeparatorBorderBrush}"
BorderThickness="1"
Background="{StaticResource SubmenuItemBackground}"
SnapsToDevicePixels="True">
<Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True" Margin="2">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
</Grid>
<Border.Effect>
<DropShadowEffect ShadowDepth="2" Color="Black"/>
</Border.Effect>
</Border>
<!--Border 3-->
<Border Margin="1,0,0,0"
x:Name="TransitionBorder"
Width="0"
Height="2"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Background="{StaticResource SubmenuItemBackground}"
SnapsToDevicePixels="False"
BorderThickness="1"
BorderBrush="{StaticResource SubmenuItemBackground}"/>
</Grid>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="true">
// Here i want to see my icon/image
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
<Setter Property="Background" Value="{StaticResource LightBackground}"/>
<Setter Property="Foreground" Value="{StaticResource Foreground}"/>
</Style>
My View model has this Property called IsSelected and when this bool value is true i want to see my image from my Resources folder.
So i know my trigger should be something like that or similar:
<DataTrigger Binding="{Binding IsSelected}" Value="true">
// Here i want to see my icon/image
</DataTrigger>
But where i need to add this image insode my Style ?
update
This is my Menu:
<Menu Name="menuInterfaces" ItemsSource="{Binding MenuItems}" Margin="0,8,0,0" Style="{StaticResource StandardMenu}">
<Menu.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type Menu:MenuItemViewModel}" ItemsSource="{Binding Path=MenuItems}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding Width}"/>
<ColumnDefinition Width="{Binding Width}"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="pack://application:,,,/Resources/checked_lightslategray.ico"
Width="12"
Height="12"
Grid.Column="0"
Margin="0,0,0,0">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="False">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding Description}"
Grid.Column="2"
Margin="0,0,0,0"/>
</Grid>
</HierarchicalDataTemplate>
</Menu.ItemTemplate>
</Menu>
Result:
enter image description here
You haven't specified where the image is supposed to go so I'll assume it's meant to go in the left-most column of your grid. You achieve this by styling the image and adding your DataTrigger to that instead:
<Style x:Key="MenuImageStyle" TargetType="{x:Type Image}">
<Setter Property="Source" Value="check.png" /> <!--Image filename-->
<Setter Property="Visibility" Value="Hidden" /> <!--Default value-->
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="true">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
And then you just add the image to your grid elements:
<Image Grid.Column="0" Style="{StaticResource MenuImageStyle}" />
I have a Stackpanel with a Image in it. The Image is partly transperent.
So i want the Background to be Red, when the mouse is not over (which works). But wen the mouse is over it should turn into green. But it doesn't work. Can you please help me out.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework">
<Style x:Key="PhoenixWindowStyle" TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="0"
ResizeBorderThickness="1"
CaptionHeight="32"
CornerRadius="0"/>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{DynamicResource DefaultBackgroundBrush}"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="MinHeight" Value="100"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid Background="{DynamicResource BorderBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
<RowDefinition Height="1"/>
</Grid.RowDefinitions>
<DockPanel Grid.Column="1" Grid.Row="0">
<TextBlock DockPanel.Dock="Left" Margin="0, 2, 0, 2" Padding="0">
<Image Width="24"
Height="24"
Margin="2"
Source="{TemplateBinding Icon}"
SnapsToDevicePixels="True"
RenderOptions.EdgeMode="Aliased" />
<Run BaselineAlignment="Center"
Text="{TemplateBinding Title}"
Foreground="{DynamicResource DefaultBackgroundBrush}"/>
</TextBlock>
<TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right">
<!--This it the part I showed before -->
<StackPanel Width="38" Height="32">
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<Image
Width="38"
Height="32"
Margin="0"
Source="../Images/FrameControlIcons/38x32/close.png"/>
</StackPanel>
<!--/////////////////////-->
</TextBlock>
</DockPanel>
<DockPanel Grid.Column="1" Grid.Row="1" >
<ContentPresenter />
</DockPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
My co-worker recognized the problem. The Problem was, that my Image was covered by the CaptionHeight of the WindowChrome. When i set the CaptionHeigt to zero it works.
So i found a solution to make both work. The CaptionHeight (To drag the window around) and the mouse event on Element that are coverd by the CaptionHeight.
I had to set this property on the affected element:
shell:WindowChrome.IsHitTestVisibleInChrome="True"
I found this Solution here:
How can I add a button to the WPF caption bar while using custom window chrome?
I have a customized TabControl:
<Window x:Class="WpfApplication2.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>
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TabStripPlacement" Value="Bottom" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TabPanel Grid.Column="0" Panel.ZIndex="1" IsItemsHost="True" Background="Transparent" />
<ItemsControl Grid.Column="1">
<ItemsControl.Items>
<Button Height="50">DOMINATES</Button>
</ItemsControl.Items>
</ItemsControl>
</Grid>
<ContentPresenter Grid.Row="0" ContentSource="SelectedContent" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border Background="LightCyan" Padding="20,0">
<TextBlock SnapsToDevicePixels="True" Text="{TemplateBinding Header}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<TabControl>
<TabItem Header="TEST 123">
<TextBlock>1</TextBlock>
</TabItem>
<TabItem Header="TEST 456">
<TextBlock>2</TextBlock>
</TabItem>
</TabControl>
</Window>
Beside the TabItems other controls are placed - which are much higher than the TabItems. How can i stretch the TabItems and place the TextBox in the middle (so that the fill the area)? Can i adjust the Padding dynamically?
http://goo.gl/xcYOY3 The red marked area should be filled and the TextBox centered. Is this possible?
Thx :)
Solution
<Window x:Class="WpfApplication2.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>
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TabStripPlacement" Value="Bottom" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="0" ContentSource="SelectedContent" />
<TabPanel Panel.ZIndex="1" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsItemsHost="True" Background="Transparent" />
<ItemsControl Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom">
<ItemsControl.ItemContainerStyle>
<Style TargetType="FrameworkElement">
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
</Style>
</ItemsControl.ItemContainerStyle>
<Button Background="LightGray" Height="70" BorderThickness="0">DOMINATES</Button>
</ItemsControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid Background="LightCyan" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabPanel}}, Path=ActualHeight}">
<TextBlock SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,0" Text="{TemplateBinding Header}" ></TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<TabControl>
<TabItem Header="TEST 123">
<TextBlock >1</TextBlock>
</TabItem>
<TabItem Header="TEST 456">
<TextBlock >2</TextBlock>
</TabItem>
</TabControl>
</Window>
I have edited your template As per you image ..please run this xaml code separately.
<Window.Resources>
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TabStripPlacement" Value="Bottom" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.ColumnSpan="2" Height="50" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="SelectedContent" />
<Grid Grid.Row="1" Grid.Column="0" Background="LightCyan">
<TabPanel Panel.ZIndex="1" HorizontalAlignment="Center" VerticalAlignment="Center" IsItemsHost="True" Background="Transparent" />
</Grid>
<ItemsControl Grid.Row="1" VerticalAlignment="Bottom" Grid.Column="1">
<ItemsControl.ItemContainerStyle>
<Style TargetType="FrameworkElement">
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
<Setter Property="Height" Value="50"></Setter>
</Style>
</ItemsControl.ItemContainerStyle>
<Button Background="LightGray" BorderThickness="0">DOMINATES</Button>
</ItemsControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid Background="LightCyan" >
<TextBlock SnapsToDevicePixels="True" Margin="5,0,5,0" >
<ContentPresenter x:Name="ContentSite" HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="Header" RecognizesAccessKey="True"/>
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<TabControl>
<TabItem Header="TEST 123">
<TextBlock >1</TextBlock>
</TabItem>
<TabItem Header="TEST 456">
<TextBlock >2</TextBlock>
</TabItem>
</TabControl>
and output from above code is http://prntscr.com/2yc51f
Update
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TabStripPlacement" Value="Bottom" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.ColumnSpan="2" Height="50" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="SelectedContent" />
<TabPanel Panel.ZIndex="1" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" IsItemsHost="True" Background="Transparent" />
<ItemsControl Grid.Row="1" VerticalAlignment="Bottom" Grid.Column="1">
<ItemsControl.ItemContainerStyle>
<Style TargetType="FrameworkElement">
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
<Setter Property="Height" Value="50"></Setter>
</Style>
</ItemsControl.ItemContainerStyle>
<Button Background="LightGray" BorderThickness="0">DOMINATES</Button>
</ItemsControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid Background="LightCyan" Height="50">
<TextBlock SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,5,0" Text="{TemplateBinding Header}" ></TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>