templatebinding

TemplateBinding not working for textbox text

核能气质少年 提交于 2019-12-05 11:41:17
I have a custom control called EnhancedTextBox which is a UserControl that has a TextBox and a Button . To the consumer I want it to mostly look like a TextBox, so I did the following: <UserControl.Template> <ControlTemplate TargetType="textBoxes:EnhancedTextBox"> ... <TextBox Text="{TemplateBinding Text}"... And in EnhancedTextBox I have public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof (String), typeof (EnhancedTextBox)); public String Text { get { return (String) GetValue(TextProperty); } set { SetValue(TextProperty, value); } } Yet, when I

TemplateBinding from a Style DataTrigger In ControlTemplate

删除回忆录丶 提交于 2019-12-05 07:22:24
In the following XAML I'm using a Rectangle with a Border as the Template for a ToggleButton. I want the BorderBrush to be a different colour to reflect the changing value of ToggleButton.IsChecked. Unfortunately my attempt here of using a TemplateBinding in the DataTrigger doesn't work. What do I need to do instead? <StackPanel Orientation="Horizontal"> <StackPanel.Resources> <ControlTemplate x:Key="ButtonAsSwatchTemplate"> <Border BorderThickness="1"> <Border.Style> <Style> <Setter Property="BorderBrush" Value="Gainsboro" /> <Style.Triggers> <!-- TemplateBinding doesn't work.--> <DataTrigger

Is it possible to use compiled binding (x:Bind) with Relative Source, Templated Parent

佐手、 提交于 2019-12-04 17:53:08
I'd like to do something like this is a Style: Value="{x:Bind MyCustomDependencyProp, RelativeSource={RelativeSource TemplatedParent}}" Is that possible? Are there any performance benefits? Using TemplateBinding does not seem to work, with a custom DependencyProperty as described elsewhere here on SO: https://stackoverflow.com/a/8657453 RelativeSource (with x:Bind) is not supported, therefore this particular scenario won't be possible (at the moment, at least). Using TemplateBinding or standard Binding to TemplatedParent (as you mentioned) are workarounds. TemplateBinding is already an

WPF DataTemplate property set at Content

瘦欲@ 提交于 2019-12-04 13:30:11
问题 New to WPF and have Tabs and in each tab the content is presented in a curved corner panel/window/whateveryouwannacallit. I wasn't sure how to do this ( Style, ControlTemplate ) but decided to go the DataTemplate way. So now I have this DataTemplate: <DataTemplate x:Key="TabContentPresenter" > <Border Margin="10" BorderBrush="{StaticResource DarkColorBrush}" CornerRadius="8" BorderThickness="2" Grid.Row="0" Padding="5" Background="{TemplateBinding Background}"> <ContentPresenter Content="

Setting Border background with a template binding

 ̄綄美尐妖づ 提交于 2019-12-04 07:26:56
Value="{TemplateBinding HeaderColor}"I've created my own control, and I'm wondering if I can bind a Border.Background to a template property. Currently i'm setting it with a StaticResource like the following: <Color x:Key="ControlMouseOverColor">green</Color> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="headerLayout"> <EasingColorKeyFrame KeyTime="0:0:6" Value="{StaticResource ControlMouseOverColor}" /> </ColorAnimationUsingKeyFrames> I'd like it be a property on my control, and be

TemplateBinding does not work in certain cases(when using TranslateTransform)

倖福魔咒の 提交于 2019-12-04 04:42:16
This is how I reproduced this problem in WPF: Create a custom control: public class TestCustomControl : Control { static TestCustomControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TestCustomControl), new FrameworkPropertyMetadata(typeof(TestCustomControl))); } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string),

WPF DataTemplate property set at Content

青春壹個敷衍的年華 提交于 2019-12-03 08:42:11
New to WPF and have Tabs and in each tab the content is presented in a curved corner panel/window/whateveryouwannacallit. I wasn't sure how to do this ( Style, ControlTemplate ) but decided to go the DataTemplate way. So now I have this DataTemplate: <DataTemplate x:Key="TabContentPresenter" > <Border Margin="10" BorderBrush="{StaticResource DarkColorBrush}" CornerRadius="8" BorderThickness="2" Grid.Row="0" Padding="5" Background="{TemplateBinding Background}"> <ContentPresenter Content="{Binding}" /> </Border> </DataTemplate> As you can see with the the background property I wan't to set the

Template Binding in Control template

邮差的信 提交于 2019-12-02 19:04:49
问题 I have the following control template. I wish to set the source property for the image control in the control template using Template Binding. But since this is a control template for button control and the button control doesn't have source property, i can't use TemplateBinding in this case. <ControlTemplate x:Key="BtnTemplate" TargetType="Button"> <Border CornerRadius="5" Margin="15" Cursor="Hand"> <StackPanel> <Image Name="Img" Style="{StaticResource ImageStyle}" Source="temp.jpg" Height=

Template Binding in Control template

拜拜、爱过 提交于 2019-12-02 09:37:41
I have the following control template. I wish to set the source property for the image control in the control template using Template Binding. But since this is a control template for button control and the button control doesn't have source property, i can't use TemplateBinding in this case. <ControlTemplate x:Key="BtnTemplate" TargetType="Button"> <Border CornerRadius="5" Margin="15" Cursor="Hand"> <StackPanel> <Image Name="Img" Style="{StaticResource ImageStyle}" Source="temp.jpg" Height="100" Width="100" Margin="5"></Image> <Label Content="{TemplateBinding Content}" Background="Transparent

WPF Nested binding in a controltemplate

这一生的挚爱 提交于 2019-12-01 06:29:05
I have successfully created a textbox that displays / collapses an error message depending upon a validation rule set in its model / vm. The code goes like this for the email for ex.: <StackPanel Grid.Row="3" Grid.Column="1"> <TextBox MaxLength="200" x:Name="mailTextBox" Style="{StaticResource SectionEditPropertyTextBox}" Text="{Binding Email, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> <ContentPresenter Visibility="{Binding ElementName=mailTextBox, Path=(Validation.HasError), Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=True }" Content="