Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Accessing template member!

Accessing template member!

Scheduled Pinned Locked Moved WPF
wpfquestiondatabasewcfcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AghaKhan
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • A AghaKhan

      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

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      This might help you: Microsoft[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups