I'm trying to build a custom ToggleIconButton with image = toggle button with image.
But some features as Command not really working.
I created the following custom class:
public class ToggleIconButton : ToggleButton
{
static ToggleIconButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ToggleIconButton), new FrameworkPropertyMetadata(typeof(ToggleIconButton)));
}
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(string), typeof(ToggleIconButton), new PropertyMetadata(default(string)));
public string Icon
{
get { return (string)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
}
and using Blend, I created the following style:
ResourceDictionary1.xaml
<SolidColorBrush x:Key="ToolBarButtonHoverBorder" Color="#3399FF"/>
<SolidColorBrush x:Key="ToolBarButtonChecked" Color="#E6F0FA"/>
<SolidColorBrush x:Key="ToolBarButtonHover" Color="#C2E0FF"/>
<SolidColorBrush x:Key="ToolBarButtonPressedBorder" Color="#3399FF"/>
<SolidColorBrush x:Key="ToolBarButtonPressed" Color="#99CCFF"/>
<Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<Image Width="22" Height="22" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding Icon, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:ToggleIconButton}}}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonChecked}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonHover}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonHoverBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonHover}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true"/>
<Condition Property="IsChecked" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonPressed}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsKeyboardFocused" Value="true"/>
<Condition Property="IsChecked" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonPressed}"/>
</MultiTrigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource ToolBarButtonPressedBorder}"/>
<Setter Property="Background" Value="{StaticResource ToolBarButtonPressed}"/>
</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="ToggleIconButtonStyle" TargetType="{x:Type controls:ToggleIconButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:ToggleIconButton}">
<Grid>
<ToggleButton Content="ToggleButton" Style="{DynamicResource ToggleButtonStyle}"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="Click!" Style="{DynamicResource ContentPresenterStyle}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ContentPresenterStyle" TargetType="{x:Type ContentPresenter}"/>
and apply the custom control:
<ToolBar VerticalAlignment="Top">
<Controls:ToggleIconButton
Content="ToggleIconButton"
Height="24"
Style="{DynamicResource ToggleIconButtonStyle}"
VerticalAlignment="Center"
Width="24"
Icon="/Images/musicNote48.png"
Command="{Binding AddCommand}"
/>
The control shown good, with the icon, but Command is not invoked. If i click on the ContentPresenter content it is... my wish is to remove the ContentPresenter with the label "Click!" and use only the icon...
Related
I have a little WPF I am creating (Self taught).
It was created in VS2021 I believe however my PC died (Motherboard).
I have reinstalled everything on a new PC and brought over the backups and have since installed VS2022.
Upon opening I am getting heaps of errors (30) on my app.xml style section.
This was working fine and weirdly still will run and compile but obviously I'm not doing something right.
Interstingly some sections are working and others aren't.
The main ones not working are referencing the SOLIDCOLORBRUSH at the top which is setting my colours for the app.
the main errors are:
Error XDG0062 'StaticResourceExtension' is not valid for Setter.Value.
The only supported MarkupExtension types are DynamicResourceExtension
and BindingBase or derived types.
Error XDG0062 The resource "brdrTeal" has an incompatible type.
Error XDG0062 'txtTitle' resource not found.
These are all referenced with {StaticResource XXXXX}
Finally this section has this error:
Error:
Error XDG0062 '{DependencyProperty.UnsetValue}' is not a valid value
for the 'System.Windows.Controls.Control.Template' property on a
Setter.
Code:
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
<Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
<Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I've included a chunk of the app.xaml file below, to see how I have laid everything out.
Keen to do this properly if this is an incorrect way to do this, as I meantioned I'm just learning this now.
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="Teal1" Color="#67DAD5" />
<SolidColorBrush x:Key="Teal2" Color="#39c0c0" />
<SolidColorBrush x:Key="Teal3" Color="#00bab3" />
<SolidColorBrush x:Key="Teal4" Color="#00a09b" />
<SolidColorBrush x:Key="Teal5" Color="#00827b" />
<SolidColorBrush x:Key="mintGreen" Color="#a4e9c6" />
<SolidColorBrush x:Key="Teal2Light" Color="#c9e9ea" />
<SolidColorBrush x:Key="LightGrey" Color="#f6f6f6" />
<SolidColorBrush x:Key="MidGrey" Color="#aaaaad" />
<SolidColorBrush x:Key="DarkGrey" Color="#56565b" />
<SolidColorBrush x:Key="Burgundy1" Color="#8C0F57" />
<SolidColorBrush x:Key="Burgundy2" Color="#deb9c7" />
<SolidColorBrush x:Key="activeAreaColour" Color="#c9e9ea"/>
<Style TargetType="{x:Type Window}">
<Setter Property="ShowInTaskbar" Value="false"/>
</Style>
<Style TargetType="{x:Type Image}" x:Key="toolTipImage">
<Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Height" Value="20"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="10 10 0 0"/>
</Style>
<Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}" >
<Setter Property="Background" Value="{DynamicResource Teal2}" />
<Setter Property="Foreground" Value="white" />
<Setter Property="BorderBrush" Value="{DynamicResource Teal5}"/>
<Setter Property="BorderThickness" Value="1 1 1 1"/>
<Setter Property="Margin" Value="-1,-1,0,0" />
<Setter Property="Height" Value="28" />
<Setter Property="Width" Value="auto"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource Teal2Light}" />
<Setter Property="BorderBrush" Value="{DynamicResource Teal5}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="black" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="12"/>
</Trigger>
</Style.Triggers>
</Style>
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Border
x:Name="Border"
Grid.ColumnSpan="2"
CornerRadius="2"
Background="{DynamicResource Teal5}"
BorderBrush="{DynamicResource Teal5}"
BorderThickness="2" />
<Border x:Name="lrgBorder"
Grid.Column="0"
CornerRadius="2,0,0,2"
Margin="1"
Background="{DynamicResource Teal2Light}"
BorderBrush="{DynamicResource Teal2Light}"
BorderThickness="0,0,1,0" />
<Path
x:Name="Arrow"
Grid.Column="1"
Fill="White"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsMouseOver" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Burgundy1}" />
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource Teal5}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="{StaticResource Burgundy2}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Burgundy1}" />
<Setter TargetName="lrgBorder" Property="Background" Value="{StaticResource LightGrey}" />
<Setter Property="Foreground" Value="{StaticResource Burgundy1}"/>
<Setter TargetName="Arrow" Property="Fill" Value="{StaticResource Burgundy2}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
<Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
</ControlTemplate>
<Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="MinWidth" Value="120"/>
<Setter Property="MinHeight" Value="20"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton
Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
ClickMode="Press">
</ToggleButton>
<ContentPresenter
Name="ContentSite"
IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="3,3,23,3"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBox x:Name="PART_EditableTextBox"
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="3,3,23,3"
Focusable="True"
Background="Transparent"
Visibility="Hidden"
IsReadOnly="{TemplateBinding IsReadOnly}"/>
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid
Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border
x:Name="DropDownBorder"
Background="{StaticResource Teal2Light}"
BorderThickness="1"
BorderBrush="{StaticResource Teal5}"/>
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource Burgundy1}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
<Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
</Trigger>
<Trigger Property="IsEditable"
Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Border" Value="{StaticResource Teal2}"/>
<Setter Property="BorderBrush" TargetName="Border" Value="#00827b"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#c9e9ea" Offset="0.0"/>
<GradientStop Color="#67DAD5" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="activeBackground" TargetType="Grid">
<Setter Property="Background" Value="{DynamicResource Teal2}"/>
</Style>
<sys:Double x:Key="fntButton">18</sys:Double>
<sys:Double x:Key="fntButtonSmall">12</sys:Double>
<sys:Double x:Key="ftnTextBox">15</sys:Double>
<Style x:Key="brdrTeal" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="{StaticResource Teal2}"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<Style x:Key="activeArea" TargetType="{x:Type Grid}">
<Setter Property="Background" Value="{StaticResource activeAreaColour}"/>
</Style>
<Style x:Key="brdrBurgundy" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="{StaticResource Burgundy1}"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0 10 0 0"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontWeight" Value="DemiBold"/>
</Style>
<!--#region TxtBoxes and passwordbox-->
<Style x:Key="txtWhite" TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="{StaticResource brdrTeal}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Margin" Value="5"/>
</Style>
<Style x:Key="txtGrey" TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
<Setter Property="Background" Value="{StaticResource LightGrey}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="5 0 0 0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Margin" Value="0 10 0 0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=MidGrey}"/>
<Setter Property="BorderThickness" TargetName="border" Value="2"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
<Setter Property="BorderThickness" TargetName="border" Value="2"/>
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
<Setter Property="Background" TargetName="border" Value="{StaticResource ResourceKey=Teal2Light}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource ResourceKey=Burgundy1}"/>
<Setter Property="FontWeight" Value="DemiBold"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="txtPassGrey" TargetType="{x:Type PasswordBox}">
<Setter Property="FontSize" Value="{StaticResource ftnTextBox}"/>
<Setter Property="Background" Value="{StaticResource LightGrey}"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
<Setter Property="BorderThickness" TargetName="border" Value="2"/>
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource ResourceKey=Teal2}"/>
<Setter Property="Background" TargetName="border" Value="{StaticResource ResourceKey=Teal2Light}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource ResourceKey=Burgundy1}"/>
<Setter Property="FontWeight" Value="DemiBold"/>
</Trigger>
</Style.Triggers>
</Style>
<!--#endregion -->
</ResourceDictionary>
</Application.Resources>
How can I remove the borders inside RadDatePicker in WPF?
I mean these grey vertical and horizontal lines inside RadCalendar.
In order to change the visual appearance of controls, you have to change their default style or control templates. If you have installed Telerik UI for WPF you can find the default styles for controls here:
C:\Program Files (x86)\Progress\<Your Telerik Version Folder>\Themes.Implicit\WPF40
From your screenshot I guess that you are using the Fluent theme. The resources for the RadDatePicker can be found in \Fluent\Themes\Telerik.Windows.Controls.Input.xaml.
What you describe in your screenshot as a border is actually the background of the calendar control. It only appears to be a border, because the buttons within the calendar have a margin that makes the background visible.
As you can see below, the LayoutRoot Grid defines a margin in the control template of CalendarButton.
<ControlTemplate TargetType="calendar:CalendarButton">
<Grid x:Name="LayoutRoot" Background="Transparent" Margin="{StaticResource CalendarButtonMargin}">
<!-- ...other template code. -->
</ControlTemplate>
In order to remove the margin, copy the CalendarButtonStyle style and remove the Margin in it.
<Style x:Key="MyCalendarButtonStyle" TargetType="calendar:CalendarButton">
<Setter Property="materialControls:MaterialAssist.CornerRadius" Value="0"/>
<Setter Property="materialControls:MaterialAssist.MouseOverBrush" Value="{telerik:FluentResource ResourceKey=MouseOverBrush}"/>
<Setter Property="materialControls:MaterialAssist.PressedBrush" Value="{telerik:FluentResource ResourceKey=PressedBrush}"/>
<Setter Property="materialControls:MaterialAssist.FocusBrush" Value="{telerik:FluentResource ResourceKey=AccentFocusedBrush}"/>
<Setter Property="materialControls:MaterialAssist.CheckedBrush" Value="{telerik:FluentResource ResourceKey=AccentBrush}"/>
<Setter Property="FontFamily" Value="{telerik:FluentResource ResourceKey=FontFamily}"/>
<Setter Property="FontSize" Value="{telerik:FluentResource ResourceKey=FontSize}"/>
<Setter Property="Foreground" Value="{telerik:FluentResource ResourceKey=MarkerBrush}"/>
<Setter Property="Background" Value="{telerik:FluentResource ResourceKey=PrimaryBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{telerik:FluentResource ResourceKey=PrimaryBackgroundBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinWidth" Value="38"/>
<Setter Property="MinHeight" Value="38"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="calendar:CalendarButton">
<Grid x:Name="LayoutRoot" Background="Transparent" Margin="0">
<Border x:Name="BorderVisual"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding materialControls:MaterialAssist.CornerRadius}"/>
<materialControls:FluentControl x:Name="Fluent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding materialControls:MaterialAssist.CornerRadius}" IsSmartClipped="True">
<ContentControl x:Name="Content"
Margin="{TemplateBinding Padding}"
Foreground="{TemplateBinding Foreground}"
ContentTemplate="{TemplateBinding ContentTemplate}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsTabStop="False"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"/>
</materialControls:FluentControl>
<Border x:Name="FocusVisual"
Background="{x:Null}"
Visibility="Collapsed"
IsHitTestVisible="False"
BorderThickness="{telerik:FluentResource ResourceKey=FocusThickness}"
BorderBrush="{TemplateBinding materialControls:MaterialAssist.FocusBrush}"
CornerRadius="{TemplateBinding materialControls:MaterialAssist.CornerRadius}"/>
<Border x:Name="SelectedVisual"
Background="{x:Null}"
Visibility="Collapsed"
IsHitTestVisible="False"
BorderThickness="{telerik:FluentResource ResourceKey=FocusThickness}"
BorderBrush="{telerik:FluentResource ResourceKey=IconBrush}"
CornerRadius="{TemplateBinding materialControls:MaterialAssist.CornerRadius}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFromCurrentView" Value="False">
<Setter TargetName="BorderVisual" Property="Background" Value="{telerik:FluentResource ResourceKey=AlternativeBrush}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{telerik:FluentResource ResourceKey=AlternativeBrush}"/>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter TargetName="FocusVisual" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="ButtonType" Value="TodayDate">
<Setter TargetName="BorderVisual" Property="Background" Value="{telerik:FluentResource ResourceKey=AccentMouseOverBrush}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{telerik:FluentResource ResourceKey=AccentMouseOverBrush}"/>
<Setter Property="materialControls:MaterialAssist.CheckedBrush" Value="{telerik:FluentResource ResourceKey=AccentPressedBrush}"/>
<Setter Property="materialControls:MaterialAssist.MouseOverBrush" Value="{telerik:FluentResource ResourceKey=AccentMouseOverBrush}"/>
<Setter Property="Foreground" Value="{telerik:FluentResource ResourceKey=MarkerInvertedBrush}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BorderVisual" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.MouseOverBrush), Mode=OneWay}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.MouseOverBrush), Mode=OneWay}"/>
</Trigger>
<Trigger Property="IsPressed" SourceName="Fluent" Value="True">
<Setter TargetName="BorderVisual" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.PressedBrush), Mode=OneWay}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.PressedBrush), Mode=OneWay}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Content" Property="Opacity" Value="{telerik:FluentResource ResourceKey=DisabledOpacity}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{telerik:FluentResource ResourceKey=MarkerInvertedBrush}"/>
<Setter TargetName="FocusVisual" Property="Visibility" Value="Collapsed"/>
<Setter TargetName="BorderVisual" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.CheckedBrush), Mode=OneWay}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(materialControls:MaterialAssist.CheckedBrush), Mode=OneWay}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Property="ButtonType" Value="TodayDate"/>
</MultiTrigger.Conditions>
<Setter TargetName="FocusVisual" Property="Visibility" Value="Visible"/>
</MultiTrigger>
<Trigger Property="ButtonType" Value="WeekNumber">
<Setter TargetName="Fluent" Property="IsEnabled" Value="False"/>
<Setter TargetName="BorderVisual" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background, Mode=OneWay}"/>
<Setter TargetName="BorderVisual" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background, Mode=OneWay}"/>
<Setter Property="Foreground" Value="{telerik:FluentResource ResourceKey=AccentBrush}"/>
</Trigger>
<Trigger Property="ButtonType" Value="WeekName">
<Setter TargetName="Fluent" Property="IsEnabled" Value="False"/>
<Setter TargetName="Content" Property="Foreground" Value="{telerik:FluentResource ResourceKey=MarkerBrush}"/>
<Setter TargetName="Content" Property="FontWeight" Value="SemiBold"/>
<Setter TargetName="LayoutRoot" Property="Margin" Value="0"/>
<Setter TargetName="BorderVisual" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Then create a style a RadCalendar style that uses this CalendarButton style.
<Style x:Key="MyCalendarStyle" TargetType="telerik:RadCalendar" BasedOn="{StaticResource {x:Type telerik:RadCalendar}}">
<Setter Property="DayButtonStyle" Value="{StaticResource MyCalendarButtonStyle}"/>
<Setter Property="MonthButtonStyle" Value="{StaticResource MyCalendarButtonStyle}"/>
<Setter Property="YearButtonStyle" Value="{StaticResource MyCalendarButtonStyle}"/>
<Setter Property="DecadeButtonStyle" Value="{StaticResource MyCalendarButtonStyle}"/>
</Style>
Then create a RadDatePicker style that uses this RadCalendar style.
<Style x:Key="MyDatePickerStyle" TargetType="{x:Type telerik:RadDatePicker}" BasedOn="{StaticResource {x:Type telerik:RadDatePicker}}">
<Setter Property="CalendarStyle" Value="{StaticResource MyCalendarStyle}"/>
</Style>
Now you can apply this style to any date picker like this.
<telerik:RadDatePicker Style="{StaticResource MyDatePickerStyle}"/>
If you want this style to be applied to all RadDatePickers in scope, you can add an implicit style.
<Style TargetType="{x:Type telerik:RadDatePicker}" BasedOn="{StaticResource MyDatePickerStyle}"/>
This is a screenshot of the resulting calendar.
For more information on styling the RadDatePicker, you can refer to the documentation.
I have various text boxes in my application, where i have used a red border to validate the data being entered. the problem is when i change tabs the red border disappears. So i am trying to apply AdornedElementPlaceholder in my styles file so that all the textboxes can adapt that behaviour. I have tried the below mentioned code but the line of code in bold (AdornedElementPlaceholder) is not working. I am using WPF and C#. Can anyone please help?
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}" >
<Setter Property="Width" Value="120" />
<Setter Property="Height" Value="25" />
<Setter Property="FontFamily" Value="Verdana"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border x:Name="bg"
CornerRadius="5"
Padding="2"
Background="{TemplateBinding Background}"
BorderBrush="{StaticResource NormalBorderBrush}"
BorderThickness="1" >
**<AdornedElementPlaceholder/>**
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush"
TargetName="bg" Value="#82CAFA"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush"
TargetName="bg" Value="#1589FF"/>
</Trigger>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background"
Value="#E5E4E2"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="SpellCheck.IsEnabled" Value="True" />
<Setter Property="Language" Value="en-gb" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="BorderBrush" Value="{StaticResource
ErrorBackground}" />
<Setter Property="ToolTip" Value="{Binding
RelativeSource={RelativeSource Self}, Path=
(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="25"/>
<Setter Property="FontFamily" Value="Verdana"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="SpellCheck.IsEnabled" Value="True"/>
<Setter Property="Language" Value="en-gb"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border CornerRadius="5" Padding="2" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<ScrollViewer x:Name="PART_ContentHost" Padding="{TemplateBinding Padding}" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#82CAFA"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="#1589FF"/>
</Trigger>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="#E5E4E2"/>
</Trigger>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="BorderBrush" Value="{StaticResource ErrorBackground}"/>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
I'm trying to make custom buttons for my application but it's not going very well.
I have the following XAML just for testing purposes:
<Style x:Key="DefBtn" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="1"
Padding="4,2"
BorderBrush="DarkGray"
CornerRadius="3"
Background="{TemplateBinding Background}">
<Grid >
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" Name="content"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="Yellow" />
<Setter Property="Foreground" Value="#FF4788c8" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
-
<Button x:Name="btnCancelTimer" Content="{Binding [LangResources.timerDetail4], FallbackValue=Cancel Timer, Mode=OneWay, Source={StaticResource localisation}}" Margin="231,0,231,32.04" VerticalAlignment="Bottom" IsCancel="True" FontSize="13.333" Click="BtnCancelTimerClick" Cursor="Hand" Foreground="#FF666666" Background="White" FontFamily="Arial" FontWeight="Bold" Width="115" Height="24" Style="{DynamicResource DefBtn}" />
I'm trying to achieve a button styling exactly like this, also including mouseover and pressed stylings on the button.
Can anyone help/guide me on how I could achieve this?
Thanks
Try using this style
<Style x:Key="DefBtn" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FFF5F5F5"/>
<Setter Property="BorderBrush" Value="#FFDCDCDC"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="#FF666666"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="8,7"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="1"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<!--TODO: Set the right colors-->
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="Yellow" />
<Setter Property="Foreground" Value="#FF4788c8" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<!--Some setters here-->
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I don't have too keen of an eye for fonts, but Arial seems to be very close. KaXaml shows this style as follows:
Also, you need to check the setters for the MouseOver, Pressed and Disabled (IsEnabled=false) triggers\states.
I've created a style for buttons in my WPF application.
However, on Vista, when a button is focused, it pulsates with a light blue that doesn't look good in the design.
How can I override this automatic pulsating?
<Style x:Key="NavigationButtonStyle" TargetType="Button">
<Setter Property="Width" Value="400"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontSize" Value="56"/>
<Setter Property="Foreground" Value="#aaa"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#ddd" />
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Foreground" Value="#aaa" />
</Trigger>
</Style.Triggers>
</Style>
Tried "IsFocused":
Adding this doesn't have any effect on Vista, the button still looks the same and is pulsating in Vista when focused:
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="Blue" />
</Trigger>
Tried "ControlTemplate" solution:
Still no effect:
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle SnapsToDevicePixels="true" Margin="2" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NavigationButtonStyle" TargetType="Button">
<Setter Property="Width" Value="400"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontSize" Value="56"/>
<Setter Property="Foreground" Value="#aaa"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#ddd" />
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Foreground" Value="#aaa" />
</Trigger>
</Style.Triggers>
</Style>
This effect is being set in response IsKeyboardFocused, not just standard focus.
In Blend if you edit the control template for a standard button, you'll see that on the IsKeyboardFocused=true trigger is responsible for this effect.
<Style x:Key="Button_NonGlow" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Microsoft_Windows_Themes:ButtonChrome SnapsToDevicePixels="true" x:Name="Chrome" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
</Microsoft_Windows_Themes:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
What you are looking for is the IsFocused trigger property. Sorry that I do not have a working example for you right here.
UPDATE:
I found this small piece of code that I once used. I am not sure if is works and I can not test it (I am on an XP box):
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle SnapsToDevicePixels="true" Margin="2" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
</Style>
Depending on your specific requirements you can simply ensure the button never gets keyboard focus by setting IsTabStop="False" and IsDefault="False".