FAQ Database Discussion Community


Assign a FrameworkElement to a control template programatically

c#,.net,wpf,controltemplate
I'm trying to custom draw a GridSplitter, and I have the following XAML code: <GridSplitter Grid.Column="1" Width="50" HorizontalAlignment="Stretch"> <GridSplitter.Template> <ControlTemplate TargetType="{x:Type GridSplitter}"> <custom:DiffSplitterCanvas /> </ControlTemplate> </GridSplitter.Template> </GridSplitter> DiffSplitterCanvas inherits from Canvas. I need to write it programatically. And I also need it to use a given already created instance of...

Replace ControlTemplate with minimum code reproduction

wpf,combobox,styling,controltemplate
I wanted to modify the standard WPF ComboBox to also show an image on the left when IsEditable is set to true. This is what I ended up with: A ResourceDictionary in a separate XAML file with these contents: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0"...

In Silverlight 5, how do I bind each DataGrid's row background color to one of its bound item's properties?

datagrid,datatemplate,silverlight-5.0,controltemplate,datatrigger
Please note that this question is specific to Silverlight 5. There are lots of similar questions floating around, but often they are about WPF or previous Silverlight versions. Others target Silverlight 5, but are about controls other than DataGrid. I have been unable to find an existing question that...

One out of two buttons using same ControlTemplate does not animate

wpf,datatemplate,controltemplate,visualstatemanager
I have a ListView that uses a DataTemplate to render out each item, with each item having an Edit and Remove button. The two buttons are templated so that they use a Path to display an icon, and animate with a storyboard when the mouse over happens. The animation changes...

Control style of each individual ToggleButton in Windows Phone 8.1

windows-phone-8.1,controltemplate,togglebutton
I am building a Windows Phone 8.1 (non SilverLight) application. I want my ToggleButtons to look different when toggled, so I have the following code: <Page.Resources> <!-- Custom style for Windows.UI.Xaml.Controls.Primitives.ToggleButton --> <Style TargetType="ToggleButton"> <Setter Property="Background" Value="{ThemeResource ToggleButtonBackgroundThemeBrush}" /> <Setter Property="Foreground" Value="{ThemeResource ToggleButtonForegroundThemeBrush}"/> <Setter Property="BorderBrush" Value="{ThemeResource...

Accessing a control within a control template in C#

c#,wpf,binding,controltemplate
WPF newbie here. I am trying to build a table that I would like to reuse for each day of the week. So I moved it to a control template. Here is the XAML: <ControlTemplate x:Key="defaultGridDesign" > <Grid HorizontalAlignment="Center" Margin="0,5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="200"/> <ColumnDefinition Width="60"/> <ColumnDefinition...

Different ControlTemplates for ErrorTemplate

c#,wpf,binding,controltemplate,idataerrorinfo
In my application I have a ControlTemplate which I use to show that the input of a TextBox is invalid. The ControlTemplate is defined as: <ControlTemplate x:Key="TextBoxErrorTemplate" TargetType="Control"> <Grid ClipToBounds="False"> <Border BorderBrush="Red" BorderThickness="1" Margin="-1"> <AdornedElementPlaceholder Name="adornedElement" /> </Border> <Image HorizontalAlignment="Right" VerticalAlignment="Top" Width="16" Height="16" Margin="0,-9,-8,0"...

WPF: Defining “Templates” for Elements Not Inherited From Control

c#,wpf,datatemplate,controltemplate,flowdocument
In this post I tried to find a way to re-template the contents of a FlowDocument. I've done several hours of research, and eventually come to this documentation on Control.Template property: The ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will...

How to center Content in a Button Template and keep mouse events in empty area

c#,wpf,button,controltemplate,contentpresenter
I am using a Button Template to customize the look and feel of my buttons like so: <ControlTemplate TargetType="Button"> <Border x:Name="Border" CornerRadius="6" BorderThickness="1"> <ContentPresenter Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" ContentSource="Content"/> </Border> </ControlTemplate> I want to center horizontally and vertically the Content, but when I do it the "empty" areas of the...

Datatrigger Change ImageBrush source

wpf,xaml,controltemplate,datatrigger
Currently am working on a reversi game and this is the ControlTemplate for a Stone on the board , Am using a DataTrigger to see who the Owner is for the Stone to set the button to the appropriate Image , But when I use TargetName on the setter (To...

Change TabItem's Header FontWeight

wpf,tabs,controltemplate
I would like to change the TabItem's Header FontWeight to Bold when IsSelected = True from my ResourceDictionary. Some Code <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TabItem}"> <Grid> <Border Name="Border" Background="White" BorderBrush="White" BorderThickness="1,1,1,0" Margin="0,0,0,-1" > <ContentPresenter x:Name="ContentSite" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/> </Border>...

WPF DatePicker DisplayDate binding does not work inside DataGrid/DataTemplate/ControlTemplate

wpf,datagrid,datepicker,datatemplate,controltemplate
It seems wpf DatePicker's DisplayDate binding does not work when datepiceker is inside datagrid or datatemplate. Here is the sample code <DataGrid x:Name="grid" AutoGenerateColumns="False" IsReadOnly="True"> <DataGrid.Columns> <DataGridTemplateColumn Header="StartDate" MinWidth="155"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding Path=StartDate}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>...

How to change MahApps.Metro dialog content template width?

wpf,xaml,modal-dialog,controltemplate,mahapps.metro
I would like to change the base template of the MahApps.Metro dialogs (or create a new dialog type), because I would like to show them in a narrow login window. Right now almost all the second words in the message are in a new row, but there are nice big...