controltemplate

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

I am writing a WPF control that subclasses a Button. I then provide a default style in Themes\generic.xaml, that looks like this (simplified): <Style TargetType="{x:Type WPFControls:MyButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type WPFControls:MyButton}"> <Button x:Name="PART_B...

WPF design UserControl / DataTemplate problem

Hi! I have a question. I have a WPF UserControl representing a Person with many fields. Some Persons can be a company. In this case I'd like to use another template with other fields. The code behind is the same, that's why I want it as a 1 control only with 2 templates. What I'd like to do is to be able to define these 2 templates wi...

Elegantly override style of ComboBox's ToggleButton in WPF

I have a question regarding how to elegantly override an arbitrary element deep inside a control's visual tree. I also have attempted to resolve it in a few different ways, but I've run into several problems with each. Usually when I try three different paths and fail at each one I go downstairs, have a coffee, and ask someone smarter ...

WPF: How to have custom button template that uses system's button background by default?

Hi, I am creating a style that changes a ControlTemplate of a Button (it actually adds arrow on the right, so that the button looks like dropdown button (which is missing in wpf)). Inside of template, I put the actual button (because I need the result to still be like button - I could change only ContentTemplate, but I need to display t...

Referencing a base types control template in xaml

I have a control derived from ComboBox, i want to use the ComboBox ControlTemplate, and just set a few values on it in xaml, namely the ItemContainerStyle. The code below doesnt work, the last setter, which im intending to apply the base ComboBox control template to this one, doesnt do anything. <Style TargetType="{x:Type local...

SilverLight - Binding a command to button within control template

I have a datagrid. Within that datagrid, I have bunch of column headers styles. Inside the control template of this style, there is a button. I need to bind a command to that button. Note that, there is also a TextBlock within the header style which I bind using element to element binding, as I will not have my viewModel in the header'...

Creating an image+text button with a control template?

I am tired of creating the same image+text button over and over again, and I would like to move the markup to a control template. Here is my problem: I need to provide template bindings to add the image and text to the templated button, and the Button control doesn't seem to have properties that I can bind to. My template looks like thi...

Create TabItems with differing content at runtime based on templates in WPF

Hello, I'm writing an application with WPF and part of it involves managing for the user various files which are used configure custom, in-house devices. I need to be able to manipulate different types of configurations in tabs in the same TabControl, meaning that the content of the TabItems must be dynamically generated. I'd like to d...

MVVM/Commands and ControlTemplates

Hi, I'm currently playing around with a MVVM/Commands and ControlTemplates. What I'm trying to do is quite simple. I want to have a list of e.g. Persons, where the user can trigger an action on each of them. But the event/commandhandler needs to be executed not on the person object e.g. because I want remove it from the list with a but...

WPF: Why shouldn't I use {TemplateBinding Margin} in ControlTemplate - is Margin meant only for element's containers?

I have created my own ControlTemplate for Button, like this: <Style x:Key="LightButtonStyle" TargetType="{x:Type ButtonBase}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ButtonBase}"> <Border x:Name="WrappingBorder" Marg...

Access ResourceDictionary items programmatically

I have a Silverlight controls assembly, called "MySilverlightControls". Several folders down into that assembly i have a class which extends a grid column from a third party vendor, let's call it "MyImageColumn.cs". I have also created a resource dictionary called Generic.xaml, this is situated in the Themes folder of the assembly. In t...

How do I replace a ControlTemplate part at runtime, in Silverlight 3?

I'm writing a custom control which uses a template defined in the resources section of my XAML and I'd like to replace one or more template parts in an instance of my control at runtime. For example, if I have a part named "ActivePart" in the control's template, how do I replace the ActivePart's FrameworkElement in an instance of the co...

WPF overriding setter properties

I'm using a style in my XAML for a label: <Style x:Key="TreatEye" TargetType="Label"> <Setter Property="Foreground" Value="#d1d1d1" /> <Setter Property="FontWeight" Value="Bold" /> <Setter Property="FontSize" Value="30" /> <Setter Property="Template"> <Setter.Value> <ControlTem...

TemplatedParent Binding in ControlTemplate.Triggers

When its text is empty, I am attempting to set the background of a custom control to a visual brush using a trigger in the ControlTemplate. The following shows the relevant code: <ControlTemplate.Triggers> <Trigger Property="Text" Value=""> <Setter TargetName="MyBorder" Property="Background"> <Setter.Value> <VisualBr...

WPF TabControl ControlTemplate

Hi, I'm looking to create a new control template for a WPF tabcontrol. The situation I have is that there will be a number of tabs in the control and the user will be able to add and delete these tabs. Ideally I would like to create something along the lines of the Firefox / IE tabs whereby you have a delete button inside the tab headi...

ListBox instead of ItemsPresenter in WPF Custom Control ?

Hi ! I'm writing a generic control template for my WPF Custom Control. But with ItemsPresenter I only got raw list of Data.. Compared to the ListBox, the ListBox has all features I need. Is it wrong to use a ListBox instead of ItemsPresenter ? What I'm after is that if I write a generic Template that uses a ListBox and in code behi...

WPF ControlTemplate partial replace

Hi ! Suppose we have a very 'XAML long' ControlTemplate for our Control. And we want to add just 1 Button to the Template. MSDN claims that 'There is no way to replace only part of the visual tree of a control'. Do I really have to copy all that ControlTemplate and add my Button to it? Or: Is there any possibility how to provide some...

How do I change the context menu on a WPF ESRI Symbol at run time?

An ESRI Symbol has a ControlTemplate and in the ControlTemplate I can specify a ContextMenu, and that works fine. However, I need to change the ContextMenu (add, remove items) at run time. ControlTemplate.FindName doesn't work because Symbol is not a FrameworkElement. I also know about Graphic.MouseLeftButtonDown, but I want the context ...

Create a ControlTemplate that will trigger on Certain values of their DependancyProperties

I want to create a ControlTemplate that will trigger on vertain values of their DependancyProperties for example a different image appear on a button Anyway there are reasons why I need DependancyProperties This is a sample of what could be in my user control .. I have just shown a simple example of an effect triggered by a property cha...

WPF TextBox.Text with MultiBinding

Hi ! I've got Custom Control with a TextBox in the default Template. The Custom Control has these 2 dependency properties (among others): SelectedValue, NullText (text to appear in the TextBox when nothing is selected and the value is provided) I'd like to set the TextBox.Text with the NullText value when the SelectedValue null is and...