controltemplate

Adding a custom dependency property to a Control Template in XAML

此生再无相见时 提交于 2019-12-05 17:54:17
I have managed to get further with my read only check box after a bit of a break and now have the functionality I want in a reasonably elegant form. The problem is I have used a bit of a hack to make it work, although this is not a disaster it would be nice to do it better. To recap: I want a regular looking checkbox that does not self check when it is clicked, instead the click event triggers a background worker that later on causes a variable to be updated. This variable is bound to checkbox.ischecked and it is then updated with the new value. I would like to use a control template based on

WPF Memory leak with derived TextBoxes

懵懂的女人 提交于 2019-12-05 17:33:23
In one of the apps of mine I have a performance problem I can’t resolve: The app is built with input controls derived from the TextBox -class, having their own ControlTemplate in Themes\Generic.xaml . My problem is, that these controls will not be released after they are no more used. If I look at them with SciTech MemoryProfiler, I see that they are hold by an instance of System.Windows.Documents.TextEditor and the TextEditor -instance is hold through the finalizer queue. Memory profiler attaches a warning to the TextEditor -instance, saying “Instance indirectly rooted by finalizer queue”.

UserControl within a ControlTemplate

佐手、 提交于 2019-12-05 15:28:05
I have a ControlTemplate for a Telerik Tile and I am overriding like below: <ControlTemplate TargetType="{x:Type ctrl:Tile}"> <Border> <local:UserControl> <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> </local:UserControl> </Border> </ControlTemplate> My user control looks like: <DockPanel> <!-- some content --> <ContentPresenter/> </DockPanel> The ControlTemplate does not display the content of the UserControl. If I change my control template to: <ControlTemplate TargetType="{x:Type ctrl:Tile}"> <Border> <StackPanel> <local

How to change control template from Style.Triggers

假如想象 提交于 2019-12-05 09:05:28
I've done it this way: <Style x:Key="Button" BasedOn="{StaticResource LoginButton}" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Border CornerRadius="4"> <Border.Background> <LinearGradientBrush EndPoint="0,1"> <GradientStop Offset="0" Color="#0863a5" /> <GradientStop Offset="1" Color="#00457d" /> </LinearGradientBrush> </Border.Background> </Border> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsEnabled" Value

When to use TemplateBinding and TemplatedParent in WPF

安稳与你 提交于 2019-12-05 06:59:23
I have a confusion over TemplateBinding and TemplatedParent. I have gone through this link also WPF TemplateBinding vs RelativeSource TemplatedParent But my doubt is when to use TemplateBinding and TemplatedParent? Thanks in advance. Rachel {TemplateBinding X} is simply a shortcut way of writing the {Binding X, RelativeSource={RelativeSource TemplatedParent}} . They evaluate to the same thing, although TemplateBinding is evaluated at compile-time while RelativeSource TemplatedParent is evaluated at run-time. Because it is evaluated at compile-time, TemplateBinding is a bit faster to evaluate

WPF - TemplateBinding doesn't recognize member content

耗尽温柔 提交于 2019-12-05 06:20:00
Alright, so I have a window with the following resources <Window.Resources> <Style TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid> <TextBlock Text="{TemplateBinding Content}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> I am getting an error saying that, "The member "Content" is not recognized or is not accessible." What am I doing wrong? You will have to define TargetType on ControlTemplate <ControlTemplate TargetType="Button"> <Grid> <TextBlock Text="{TemplateBinding Content}"/> </Grid> </ControlTemplate>

Clear wpf listbox selection using button in control template and no codebehind

限于喜欢 提交于 2019-12-04 21:24:53
I want to create a Style for a WPF ListBox that includes a Button in the ControlTemplate that the user can click on and it clears the ListBox selection. I dont want to use codebehind so that this Style can be applied to any ListBox . I have tried using EventTrigger s and Storyboard s and it has proved problematic as it only works first time and stopping the Storyboard sets the previous selection back. I know I could use a user control but I want to know if it is possible to achieve this using only a Style . It is not possible to achieve this using XAML and only the classes provided by the .NET

Access control in style from code [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-04 18:51:12
This question already has an answer here: How do I access an element of a control template from within code-behind 2 answers If I have a style that defines a control template, and in this I have a control, let's say a button, is there any way to access the button from code behind of the styled control? Thank you guys! =) Say you have a style defined as follows <Style x:Key="myStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Button x:Name="myTemplatedButton" Content="my templated button"/> </ControlTemplate> </Setter.Value> </Setter> </Style>

WPF - Use a ControlTemplate resource within a Style

若如初见. 提交于 2019-12-04 18:42:12
问题 When creating a Style, is it possible to set the ControlTemplate property to a previously defined resource? For example, if I had the following in a ResourceDictionary: <ControlTemplate x:Key="MyControlTemplate" TargetType="{x:Type Button}"> ... </ControlTemplate> And then later wanted to use it in a Style like this: <Style x:Key="MyStyle" TargetType="{x:Type Button}"> <Setter Property="Template" Value="???"/> </Style> Is that possible? 回答1: I believe this will work: <Style x:Key="MyStyle"

How apply MinWidth for ListView columns in WPF in control template?

佐手、 提交于 2019-12-04 09:24:39
Following the answer to a similar question here , I was able to set the MinWidth on the XAML page. What I would like to do is accomplish this in the control template for all GridViewColumn's in all ListView's. Is this possible? Update: I tried a simple bit of sample code below, but it does not work: <Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style TargetType="{x:Type GridViewColumnHeader}" > <Setter Property=