Accessing template member!
-
I have a template and would like to access a UIElement. Because it is a template, it is not an object unless it is a static object. How can I create a static object in a template? The x:Name=”someName” are only to access inside template NOT outside. So we get an error when we try to access from a class. i.e. in constructor I can’t access someName. This also means that I cannot write a function when there is a change. How this can be done? Best regards Agha <Button x:Class="WpfApplication1.DoubleCharBtn" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Button.Template> <ControlTemplate> <Border x:Name="br" Background="Blue" CornerRadius="3" BorderBrush="Black"> <StackPanel Orientation="Vertical"> <TextBlock x:Name="TextUpperChar" HorizontalAlignment="Center" Text="{Binding UpperLetter}" /> <TextBlock x:Name="TextLowerChar" HorizontalAlignment="Center" Text="{Binding LowerLetter}" /> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="Button.IsPressed" Value="True"> <Setter TargetName="br" Property="Background" Value="Red"/> <Setter TargetName="TextUpperChar" Property="Background"> <Setter.Value> <LinearGradientBrush> <GradientStop Offset="1" Color="DarkBlue"/> <GradientStop Offset="0.5" Color="Blue"/> <GradientStop Offset="0" Color="DarkBlue"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> namespace WpfApplication1 { /// <summary> /// Interaction logic for DoubleCharBtn.xaml /// </summary> public partial class DoubleCharBtn : Button { internal static readonly DependencyProperty UpperCharProperty = DependencyProperty.Register( "UpperChar", typeof(char), typeof(DoubleCharBtn), new Framew
-
I have a template and would like to access a UIElement. Because it is a template, it is not an object unless it is a static object. How can I create a static object in a template? The x:Name=”someName” are only to access inside template NOT outside. So we get an error when we try to access from a class. i.e. in constructor I can’t access someName. This also means that I cannot write a function when there is a change. How this can be done? Best regards Agha <Button x:Class="WpfApplication1.DoubleCharBtn" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Button.Template> <ControlTemplate> <Border x:Name="br" Background="Blue" CornerRadius="3" BorderBrush="Black"> <StackPanel Orientation="Vertical"> <TextBlock x:Name="TextUpperChar" HorizontalAlignment="Center" Text="{Binding UpperLetter}" /> <TextBlock x:Name="TextLowerChar" HorizontalAlignment="Center" Text="{Binding LowerLetter}" /> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="Button.IsPressed" Value="True"> <Setter TargetName="br" Property="Background" Value="Red"/> <Setter TargetName="TextUpperChar" Property="Background"> <Setter.Value> <LinearGradientBrush> <GradientStop Offset="1" Color="DarkBlue"/> <GradientStop Offset="0.5" Color="Blue"/> <GradientStop Offset="0" Color="DarkBlue"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> namespace WpfApplication1 { /// <summary> /// Interaction logic for DoubleCharBtn.xaml /// </summary> public partial class DoubleCharBtn : Button { internal static readonly DependencyProperty UpperCharProperty = DependencyProperty.Register( "UpperChar", typeof(char), typeof(DoubleCharBtn), new Framew