Skip to content

Instantly share code, notes, and snippets.

@treytomes
Created February 29, 2016 16:55
Show Gist options
  • Save treytomes/2ce75c2244c56f59ab6f to your computer and use it in GitHub Desktop.
Save treytomes/2ce75c2244c56f59ab6f to your computer and use it in GitHub Desktop.
Make the Xceed WPF Toolkit SplitButton control look correct on a toolbar.
Imports System.Globalization
Namespace Utility
Public Class InverseBooleanConverter
Implements IValueConverter
Public Function Convert(pValue As Object, pTargetType As Type, pParameter As Object, pCulture As CultureInfo) As Object Implements IValueConverter.Convert
Return Not DirectCast(pValue, Boolean)
End Function
Public Function ConvertBack(pValue As Object, pTargetType As Type, pParameter As Object, pCulture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Not DirectCast(pValue, Boolean)
End Function
End Class
End Namespace
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:util="clr-namespace:Utility"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit">
<util:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<LinearGradientBrush x:Key="ColorPickerDarkBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0" />
<GradientStop Color="#FF8399A9" Offset="0.375" />
<GradientStop Color="#FF718597" Offset="0.375" />
<GradientStop Color="#FF617584" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="PopupBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="0" Color="#FFffffff" />
<GradientStop Offset="1" Color="#FFE8EBED" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="SplitButtonToolbarStyle" TargetType="xctk:SplitButton">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="xctk:SplitButton">
<Grid x:Name="MainGrid" SnapsToDevicePixels="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="PART_ActionButton" Margin="0" Padding="{TemplateBinding Padding}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
<ContentPresenter Name="ActionButtonContent" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" RecognizesAccessKey="true"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
</Button>
<ToggleButton x:Name="PART_ToggleButton" Grid.Column="1" IsTabStop="False" IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBooleanConverter}}">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<ContentPresenter />
</ControlTemplate>
</ToggleButton.Template>
<Grid>
<xctk:ButtonChrome x:Name="ToggleButtonChrome" Background="Transparent" BorderThickness="1,0,0,0" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
Padding="1,0,1,0" RenderChecked="{TemplateBinding IsOpen}" RenderEnabled="{TemplateBinding IsEnabled}"
RenderMouseOver="{Binding IsMouseOver, ElementName=PART_ToggleButton}" RenderPressed="{Binding IsPressed, ElementName=PART_ToggleButton}">
<Grid x:Name="arrowGlyph" IsHitTestVisible="False" Margin="4,3,4,3">
<Path x:Name="Arrow" Width="7" Height="4" Fill="Black" Data="M 0,0 L 4,4 8,0 Z" />
</Grid>
</xctk:ButtonChrome>
</Grid>
</ToggleButton>
</Grid>
<Popup x:Name="PART_Popup" HorizontalOffset="1" VerticalOffset="1" AllowsTransparency="True" StaysOpen="False" Placement="Bottom" Focusable="False"
IsOpen="{Binding IsChecked, ElementName=PART_ToggleButton}">
<Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}">
<ContentPresenter x:Name="PART_ContentPresenter" Content="{TemplateBinding DropDownContent}" />
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Fill" TargetName="Arrow" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment