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.
Related
I make an application in WPF where I need to use the TabControl to switching between Contents. But due to design purpose my content of the Tab items are in same horizontal line followed by the Tab item header.
Here is the code of my Mainwindow.xaml
<Grid Width="635" HorizontalAlignment="Left" Height="458" VerticalAlignment="Top" Margin="0,61,0,0" >
<TabControl Margin="-1" BorderThickness="0" Background="#222222" >
<TabItem Style="{StaticResource TabItemDefaults}" Header="File manager" FontSize="10" Foreground="#efefef" Margin="5,0,0,0" Width="97" Height="20" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" >
<Grid>
<Label Name="Folder" Content="Folder:" FontSize="10" Foreground="#efefef" Height="20" Width="40" Margin="-571,-367,0,0" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" />
<Button Name ="FolderSelect" Width="532" HorizontalAlignment="Left" VerticalAlignment="Top" Height="33" Margin="85,17,0,0" Background="#1a1a1a"
materialDesign:ShadowAssist.ShadowDepth="Depth0" materialDesign:RippleAssist.Feedback="Transparent" BorderThickness="0" UseLayoutRounding="True"
></Button>
<Label Name="ShowFolders" Content=".." Margin="-479,59,0,0" Background="#1a1a1a" Width="168" Height="373" Foreground="#efefef" ></Label>
<Button
Style="{StaticResource MaterialDesignRaisedButton}"
Width="65" HorizontalAlignment="Left" Height="25" Background="#FF403D3D" Margin="16,292,0,0"
ToolTip="Resource name: MaterialDesignRaisedButton">
<materialDesign:PackIcon Kind="PlusThick" />
</Button>
<Button
Style="{StaticResource MaterialDesignRaisedButton}"
Width="65" HorizontalAlignment="Left" Height="25" Background="#FF403D3D" Margin="82,292,0,0"
ToolTip="Open output folder">
<materialDesign:PackIcon Kind="FolderUpload" />
</Button>
<Label Content="Video recordings:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="269.2,-22,0,0" Foreground="#efefef" FontSize="10" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" />
</Grid>
</TabItem>
<TabItem Style="{StaticResource TabItemDefaults}" Header ="Preview" FontSize="10" Foreground="#efefef" Width="67" Height="20" Margin="-8,0,0,0" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" >
<Grid>
<CheckBox Content="Draggable mode" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="520,-22,0,0" Width="110" />
</Grid>
</TabItem>
</TabControl>
</Grid>
Both Tab Control and Tab items are made by control template which I declare in App.xaml.
And here is the code of Tab Control which I separately declare in App.xaml -
<Style TargetType="{x:Type TabControl}" x:Key="TabControlDefaults" x:Name="NewTabcontrol" >
<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>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Border.BorderBrush).
(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="#FFAAAAAA" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TabPanel x:Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
Margin="0,0,4,-1"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent" />
<Border x:Name="Border"
Grid.Row="1"
BorderThickness="1"
CornerRadius="2"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="{DynamicResource ContentAreaColorLight}"
Offset="0" />
<GradientStop Color="{DynamicResource ContentAreaColorDark}"
Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}"/>
</Border.BorderBrush>
<ContentPresenter x:Name="PART_SelectedContentHost"
Margin="4"
ContentSource="SelectedContent" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here is the code of Tab Items which I separately declare in App.xaml -
<Style TargetType="{x:Type TabItem}" x:Key="TabItemDefaults" x:Name="NewTabitem" >
<Setter Property="Foreground" Value="#bababa" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid x:Name="Panel" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local" >
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<!-- <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" /> -->
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{TemplateBinding Content}">
<TextBlock.TextDecorations>
<TextDecoration PenOffset="4" PenOffsetUnit="Pixel" >
<TextDecoration.Pen>
<Pen Brush="#673ab7" Thickness="4" />
</TextDecoration.Pen>
</TextDecoration>
</TextBlock.TextDecorations>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Panel" Property="Background" Value="#212121" />
<Setter Property="Foreground" Value="WhiteSmoke"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And my question is the checkbox (I give a red circle) are not functioning properly. I know the main cause is the check box is outside of the tab panel of the Tab Control. But I have to place it there for the design purpose of my Application.
So, how I give a custom shape to the tab panel of the Tab control so that I perfectly dock my content elements where I want.
Your CheckBox can't be selected , you can use DataTrigger to make the chexkbox Visible or Hidden depending on the Preview TabItem selected or not.
I do some update for your MainWindow.xaml to make the checkbox can be selected.
<StackPanel Width="635" HorizontalAlignment="Left" Height="458" VerticalAlignment="Top" Margin="0,61,0,0" >
<CheckBox Content="Draggable mode" HorizontalAlignment="Right" VerticalAlignment="Top" Width="110" >
<CheckBox.Style>
<Style TargetType="CheckBox">
<Setter Property="Visibility" Value="Hidden"></Setter>
<Setter Property="IsEnabled" Value="False"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=myTabControl,Path=SelectedItem.Header}" Value="Preview" >
<Setter Property="Visibility" Value="Visible"></Setter>
<Setter Property="IsEnabled" Value="True"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
<TabControl BorderThickness="0" Background="#222222" Name="myTabControl" SelectionChanged="myTabControl_SelectionChanged">
<TabItem Style="{StaticResource TabItemDefaults}" Header="File manager" FontSize="10" Foreground="#efefef" Margin="5,0,0,0" Width="97" Height="20" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" >
<Grid Height="300">
</Grid>
</TabItem>
<TabItem Style="{StaticResource TabItemDefaults}" Header ="Preview" FontSize="10" Foreground="#efefef" Width="67" Height="20" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" >
<Grid Height="300">
</Grid>
</TabItem>
</TabControl>
</StackPanel>
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"
>
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>
Would somebody know how to recreate this button style in WPF? As I do not know how to make the different compartments. As well as the 2 different texts and text styles?
To solve your question definitely need to use the Style and Template for the Button. But how exactly does he look like? Decisions may be several. For example, Button are two texts to better define the relevant TextBlocks? Can be directly in the template, but then use the buttons will be limited, because the template can be only one ContentPresenter. I decided to do things differently, to identify one ContentPresenter with an icon in the form of a Path, and the content is set using the buttons on the side.
The style:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#373737" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="4" Background="{TemplateBinding Background}">
<Grid>
<Path x:Name="PathIcon" Width="15" Height="25" Stretch="Fill" Fill="#4C87B3" HorizontalAlignment="Left" Margin="17,0,0,0" Data="F1 M 30.0833,22.1667L 50.6665,37.6043L 50.6665,38.7918L 30.0833,53.8333L 30.0833,22.1667 Z "/>
<ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E59400" />
<Setter Property="Foreground" Value="White" />
<Setter TargetName="PathIcon" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="OrangeRed" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Sample of using:
<Button Width="200" Height="50" VerticalAlignment="Top" Margin="0,20,0,0" />
<Button.Content>
<StackPanel>
<TextBlock Text="Watch Now" FontSize="20" />
<TextBlock Text="Duration: 50m" FontSize="12" Foreground="Gainsboro" />
</StackPanel>
</Button.Content>
</Button>
Output
It is best to StackPanel determine the Resources and set the Button so:
<Window.Resources>
<StackPanel x:Key="MyStackPanel">
<TextBlock Name="MainContent" Text="Watch Now" FontSize="20" />
<TextBlock Name="DurationValue" Text="Duration: 50m" FontSize="12" Foreground="Gainsboro" />
</StackPanel>
</Window.Resources>
<Button Width="200" Height="50" Content="{StaticResource MyStackPanel}" VerticalAlignment="Top" Margin="0,20,0,0" />
The question remains with setting the value for TextBlock Duration, because this value must be dynamic. I implemented it using attached DependencyProperty. Set it to the window, like that:
<Window Name="MyWindow" local:MyDependencyClass.CurrentDuration="Duration: 50m" ... />
Using in TextBlock:
<TextBlock Name="DurationValue" Text="{Binding ElementName=MyWindow, Path=(local:MyDependencyClass.CurrentDuration)}" FontSize="12" Foreground="Gainsboro" />
In fact, there is no difference for anyone to determine the attached DependencyProperty, because it is the predominant feature.
Example of set value:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyDependencyClass.SetCurrentDuration(MyWindow, "Duration: 101m");
}
A complete listing of examples:
XAML
<Window x:Class="ButtonHelp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ButtonHelp"
Name="MyWindow"
Title="MainWindow" Height="350" Width="525"
WindowStartupLocation="CenterScreen"
local:MyDependencyClass.CurrentDuration="Duration: 50m">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="#373737" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontFamily" Value="./#Segoe UI" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="4" Background="{TemplateBinding Background}">
<Grid>
<Path x:Name="PathIcon" Width="15" Height="25" Stretch="Fill" Fill="#4C87B3" HorizontalAlignment="Left" Margin="17,0,0,0" Data="F1 M 30.0833,22.1667L 50.6665,37.6043L 50.6665,38.7918L 30.0833,53.8333L 30.0833,22.1667 Z "/>
<ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E59400" />
<Setter Property="Foreground" Value="White" />
<Setter TargetName="PathIcon" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="OrangeRed" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<StackPanel x:Key="MyStackPanel">
<TextBlock Name="MainContent" Text="Watch Now" FontSize="20" />
<TextBlock Name="DurationValue" Text="{Binding ElementName=MyWindow, Path=(local:MyDependencyClass.CurrentDuration)}" FontSize="12" Foreground="Gainsboro" />
</StackPanel>
</Window.Resources>
<Grid>
<Button Width="200" Height="50" Content="{StaticResource MyStackPanel}" VerticalAlignment="Top" Margin="0,20,0,0" />
<Button Content="Set some duration" Style="{x:Null}" Width="140" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Click="Button_Click" />
</Grid>
Code behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MyDependencyClass.SetCurrentDuration(MyWindow, "Duration: 101m");
}
}
public class MyDependencyClass : DependencyObject
{
public static readonly DependencyProperty CurrentDurationProperty;
public static void SetCurrentDuration(DependencyObject DepObject, string value)
{
DepObject.SetValue(CurrentDurationProperty, value);
}
public static string GetCurrentDuration(DependencyObject DepObject)
{
return (string)DepObject.GetValue(CurrentDurationProperty);
}
static MyDependencyClass()
{
PropertyMetadata MyPropertyMetadata = new PropertyMetadata("Duration: 0m");
CurrentDurationProperty = DependencyProperty.RegisterAttached("CurrentDuration",
typeof(string),
typeof(MyDependencyClass),
MyPropertyMetadata);
}
}
Here's my attempt. Looks more similar to the OP's sample and provides settable properties for icon (FrameworkElement), title (string) and subtitle (string). The output looks like this:
Here's XAML:
<Button x:Class="Controls.FancyButton"
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:Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Width="300" Height="80"
BorderBrush="{x:Null}" BorderThickness="0">
<Button.Effect>
<DropShadowEffect BlurRadius="12" Color="Gray" Direction="270" Opacity=".8" ShadowDepth="3" />
</Button.Effect>
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid Width="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=ActualHeight}">
<Border x:Name="MainBorder" CornerRadius="3" Grid.ColumnSpan="2" Margin="0,0,4,4" BorderBrush="Black" BorderThickness="1">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF5E5E5E" Offset="0" />
<GradientStop Color="#FF040404" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Border CornerRadius="2" Margin="0" BorderBrush="LightGray" BorderThickness="0,1,0,0" Grid.ColumnSpan="2" Grid.RowSpan="2" />
<Line X1="10" Y1="0" X2="10" Y2="10" Stretch="Fill" Grid.Column="0" HorizontalAlignment="Right" Stroke="#0C0C0C" Grid.RowSpan="2" />
<Line X1="10" Y1="0" X2="10" Y2="10" Stretch="Fill" Grid.Column="1" HorizontalAlignment="Left" Grid.RowSpan="2">
<Line.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#4D4D4D" Offset="0" />
<GradientStop Color="#2C2C2C" Offset="1" />
</LinearGradientBrush>
</Line.Stroke>
</Line>
<ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Grid.RowSpan="2">
<ContentControl.Content>
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Image">
<Binding.FallbackValue>
<Path Data="M0,0 L30,15 L0,30Z">
<Path.Effect>
<DropShadowEffect Direction="50" ShadowDepth="2" />
</Path.Effect>
<Path.Fill>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="#4B86B2" Offset="0" />
<GradientStop Color="#477FA8" Offset="1" />
</LinearGradientBrush>
</Path.Fill>
</Path>
</Binding.FallbackValue>
</Binding>
</ContentControl.Content>
</ContentControl>
<Grid Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="Title" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue='Watch Now'}" Grid.Column="1" VerticalAlignment="Bottom" FontFamily="Calibri" FontWeight="Bold" FontSize="28" Foreground="White" Margin="20,0,0,0" />
<TextBlock x:Name="SubTitle" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SubTitle, FallbackValue='Duration: 50 min'}" Grid.Column="1" Grid.Row="1" VerticalAlignment="top" FontFamily="Calibri" FontSize="14" Foreground="White" Margin="20,0,0,0" />
</Grid>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Title" Property="TextDecorations" Value="Underline" />
<Setter TargetName="SubTitle" Property="TextDecorations" Value="Underline" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="MainBorder" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF5E5E5E" Offset="0" />
<GradientStop Color="#FFA4A4A4" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
Here's the code-behind:
using System.Windows;
using System.Windows.Controls;
namespace Controls
{
public partial class FancyButton : Button
{
public FancyButton()
{
InitializeComponent();
}
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(FancyButton), new FrameworkPropertyMetadata("Title", FrameworkPropertyMetadataOptions.AffectsRender));
public string SubTitle
{
get { return (string)GetValue(SubTitleProperty); }
set { SetValue(SubTitleProperty, value); }
}
public static readonly DependencyProperty SubTitleProperty =
DependencyProperty.Register("SubTitle", typeof(string), typeof(FancyButton), new FrameworkPropertyMetadata("SubTitle", FrameworkPropertyMetadataOptions.AffectsRender));
public FrameworkElement Image
{
get { return (FrameworkElement)GetValue(ImageProperty); }
set { SetValue(ImageProperty, value); }
}
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(FrameworkElement), typeof(FancyButton), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
}
}
Here is how to use it:
<controls:FancyButton Grid.Row="1" HorizontalAlignment="Right" Margin="3" Title="Watch Now" SubTitle="Duration: 50 min">
<controls:FancyButton.Image>
<Path Data="M0,0 L30,15 L0,30Z">
<Path.Effect>
<DropShadowEffect Direction="50" ShadowDepth="2" />
</Path.Effect>
<Path.Fill>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="#4B86B2" Offset="0" />
<GradientStop Color="#477FA8" Offset="1" />
</LinearGradientBrush>
</Path.Fill>
</Path>
</controls:FancyButton.Image>
</controls:FancyButton>
<!--Customize button -->
<LinearGradientBrush x:Key="Buttongradient" StartPoint="0.500023,0.999996" EndPoint="0.500023,4.37507e-006">
<GradientStop Color="#5e5e5e" Offset="1" />
<GradientStop Color="#0b0b0b" Offset="0" />
</LinearGradientBrush>
<Style x:Key="hhh" TargetType="{x:Type Button}">
<Setter Property="Background" Value="{DynamicResource Buttongradient}"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="4" Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="0.5">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="2"></DropShadowEffect>
</Border.Effect>
<Grid>
<Path Width="9" Height="16.5" Stretch="Fill" Fill="#000" HorizontalAlignment="Left" Margin="16.5,0,0,0" Data="F1 M 30.0833,22.1667L 50.6665,37.6043L 50.6665,38.7918L 30.0833,53.8333L 30.0833,22.1667 Z " Opacity="0.2">
</Path>
<Path x:Name="PathIcon" Width="8" Height="15" Stretch="Fill" Fill="#4C87B3" HorizontalAlignment="Left" Margin="17,0,0,0" Data="F1 M 30.0833,22.1667L 50.6665,37.6043L 50.6665,38.7918L 30.0833,53.8333L 30.0833,22.1667 Z ">
<Path.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="5"></DropShadowEffect>
</Path.Effect>
</Path>
<Line HorizontalAlignment="Left" Margin="40,0,0,0" Name="line4" Stroke="Black" VerticalAlignment="Top" Width="2" Y1="0" Y2="640" Opacity="0.5" />
<ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E59400" />
<Setter Property="Foreground" Value="White" />
<Setter TargetName="PathIcon" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="OrangeRed" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
In this day and age of mouse driven computers and tablets with touch screens etc, it is often forgotten to cater for input via keyboard only. A button should support a focus rectangle (the dotted rectangle when the button has focus) or another shape matching the button shape.
To add a focus rectangle to the button, use this XAML (from this site).
Focus rectangle style:
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Rectangle Margin="2" StrokeThickness="1" Stroke="#60000000" StrokeDashArray="1 2" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Applying the style to the button:
<Style TargetType="Button">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}" />
...
<Button x:Name="mybtnSave" FlowDirection="LeftToRight" HorizontalAlignment="Left" Margin="813,614,0,0" VerticalAlignment="Top" Width="223" Height="53" BorderBrush="#FF2B3830" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="B Titr" FontSize="15" FontWeight="Bold" BorderThickness="2" TabIndex="107" Click="mybtnSave_Click" >
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF080505" Offset="1"/>
<GradientStop Color="White" Offset="0.536"/>
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
<DropShadowEffect/>
</Button.Effect>
<StackPanel HorizontalAlignment="Stretch" Cursor="Hand" >
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF3ED82E" Offset="0"/>
<GradientStop Color="#FF3BF728" Offset="1"/>
<GradientStop Color="#FF212720" Offset="0.52"/>
</LinearGradientBrush>
</StackPanel.Background>
<Image HorizontalAlignment="Left" Source="image/Append Or Save 3.png" Height="36" Width="203" />
<TextBlock HorizontalAlignment="Center" Width="145" Height="22" VerticalAlignment="Top" Margin="0,-31,-35,0" Text="Save Com F12" FontFamily="Tahoma" FontSize="14" Padding="0,4,0,0" Foreground="White" />
</StackPanel>
</Button>
I have the following defined in my control:
<Style TargetType="primitives:CalendarDayButton" x:Key="EventCalendarDayButton">
<Setter Property="Background" Value="#FFBADDE9"/>
<Setter Property="MinWidth" Value="5"/>
<Setter Property="MinHeight" Value="5"/>
<Setter Property="FontSize">
<Setter.Value>
<Binding Path="DayFontSize">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor" AncestorType="{x:Type toolkit:Calendar}" />
</Binding.RelativeSource>
</Binding>
</Setter.Value>
</Setter>
<Setter Property="HorizontalContentAlignment" Value="Right"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="primitives:CalendarDayButton">
<Grid MouseDown="Grid_MouseDown">
<Grid.RowDefinitions>
<RowDefinition Height="18" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle x:Name="SelectedBackground" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}"/>
<Rectangle x:Name="Background" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}" />
<Rectangle x:Name="InactiveBackground" Grid.Row="1" RadiusX="1" RadiusY="1" Opacity="0" Fill="#FFA5BFE1"/>
<Border>
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop x:Name="StartGradient" Color="#FFD5E2F2" Offset="0"/>
<GradientStop x:Name="EndGradient" Color="#FFB9C9DD" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<ContentPresenter x:Name="NormalText" Margin="5,1,5,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<TextElement.Foreground>
<SolidColorBrush x:Name="selectedText" Color="#FF333333" />
</TextElement.Foreground>
</ContentPresenter>
</Border>
<Rectangle x:Name="Border" StrokeThickness="0.5" Grid.RowSpan="2" SnapsToDevicePixels="True">
<Rectangle.Stroke>
<SolidColorBrush x:Name="BorderBrush" Color="#FF5D8CC9"/>
</Rectangle.Stroke>
</Rectangle>
<Path x:Name="Blackout" Grid.Row="1" Opacity="0" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Fill="#FF000000" Stretch="Fill" Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z"/>
<Rectangle Width="0" x:Name="DayButtonFocusVisual" Grid.Row="1" Visibility="Collapsed" IsHitTestVisible="false" RadiusX="1" RadiusY="1" Stroke="#FF45D6FA"/>
<Button x:Name="ActivateDayViewOnDay" Grid.Row="0" Opacity="0.3" Height="15" Margin="1,1,1,1" PreviewMouseLeftButtonDown="DayView_Click" />
<ScrollViewer Grid.Row="1" >
<ScrollViewer.Content>
<local:TestListBox
x:Name="eventsLbx"
Background="Transparent"
BorderBrush="Transparent"
>
<local:TestListBox.ItemsSource>
<MultiBinding Converter="{StaticResource calendarEventsConverter}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:EventCalendar}}" Path="CalendarEvents"/>
<Binding RelativeSource="{RelativeSource Mode=Self}" Path="DataContext"/>
</MultiBinding>
</local:TestListBox.ItemsSource>
<local:TestListBox.ItemTemplate>
<DataTemplate>
<TextBlock TextTrimming="CharacterEllipsis" HorizontalAlignment="Center" FontSize="12" Text="{Binding Text}" />
</DataTemplate>
</local:TestListBox.ItemTemplate>
</local:TestListBox>
</ScrollViewer.Content>
</ScrollViewer>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="eventsLbx" Property="HasItems" Value="False">
<Setter TargetName="eventsLbx" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now if there are more items than are visible, then the scrollviewer appears properly but the user CANNOT drag the scrollviewer middle button for scrolling.
The user can click on the arrows at the end of the scrollviewer to scroll but he cannot click the bar that appears on the scrollbar and drag it to actually scroll the contents.
I cannot figure out why this is happening...
If you want to scroll the items in your ListBox, you do not need to wrap it in a ScrollViewer. The ListBox natively supports scrolling. That means, if your ListBox is too small to display all its items, it automatically adds ScrollBars to the side.
Your ScrollViewer and ListBox are inside a Grid, and you have some code behind the MouseDown event of that Grid.
<Grid MouseDown="Grid_MouseDown">
Something you're doing in that method may be getting in the way of the mouse mechanisms of the ScrollViewer, disrupting event bubbling or something like that.
Check your code-behind, or post it here so we can help you with it :)