WPF ControlTemplate: How to provide a default value for TemplateBinding?

You can just define setters on your style for the two properties in question. For example, some general definitions: <LinearGradientBrush x:Key=”ButtonNormalBackground” EndPoint=”0,1″ StartPoint=”0,0″> <GradientStop Color=”#F3F3F3″ Offset=”0″/> <GradientStop Color=”#EBEBEB” Offset=”0.5″/> <GradientStop Color=”#DDDDDD” Offset=”0.5″/> <GradientStop Color=”#CDCDCD” Offset=”1″/> </LinearGradientBrush> <SolidColorBrush x:Key=”ButtonNormalBorder” Color=”#FF707070″/> Then, in your style definition: <Setter Property=”Background” Value=”{StaticResource ButtonNormalBackground}” /> <Setter Property=”BorderBrush” Value=”{StaticResource ButtonNormalBorder}” />

Replace part of default template in WPF

Unfortunately, I think you have to replace the entire template: From MSDN: http://msdn.microsoft.com/en-us/library/aa970773.aspx Controls in Windows Presentation Foundation (WPF) have a ControlTemplate that contains the visual tree of that control. You can change the structure and appearance of a control by modifying the ControlTemplate of that control. There is no way to replace only part … Read more

In WPF, why doesn’t TemplateBinding work where Binding does?

Found this forum post on MSDN: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0bb3858c-30d6-4c3d-93bd-35ad0bb36bb4/ It says this: A TemplateBinding is an optimized form of a Binding for template scenarios, analogous to a Binding constructed with {Binding RelativeSource={RelativeSource TemplatedParent}} Note from OP: Contrary to what it says in the documentation, in actuality, it should be this… {Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay} I filed a … Read more

How to create a WPF Window without a border that can be resized via a grip only?

If you set the AllowsTransparency property on the Window (even without setting any transparency values) the border disappears and you can only resize via the grip. <Window xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Width=”640″ Height=”480″ WindowStyle=”None” AllowsTransparency=”True” ResizeMode=”CanResizeWithGrip”> <!– Content –> </Window> Result looks like:

Difference between Control Template and DataTemplate in WPF

Typically a control is rendered for its own sake, and doesn’t reflect underlying data. For example, a Button wouldn’t be bound to a business object – it’s there purely so it can be clicked on. A ContentControl or ListBox, however, generally appear so that they can present data for the user. A DataTemplate, therefore, is … Read more