locked
TemplateBinding Dependency Properties in UserControls RRS feed

  • Question

  •  Hi,

    I have a user control that has a button set with the Style below. In fact I am trying to implement a LinkButton. It is working OK but I would like to make the text underlined when the mouse passes over it:

    <Style TargetType="Button" x:Key="LinkButtonStyle">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="Button">
          <TextBlock x:Name="innerTextBlock" Text="{TemplateBinding Content}"
                     TextDecorations="{TemplateBinding TextDecoration}"
                     Width="Auto" Height="Auto" Margin="0,0,0,0"
                     Foreground="#FFE5E5E5" FontSize="11" Cursor="Hand" />
          </ControlTemplate>
       </Setter.Value>
      </Setter>
    </Style>

    The Button is defined like this:
    <Button x:Name="linkButton" Content="linkButton" BorderThickness="0,0,0,0"
            Style="{StaticResource LinkButtonStyle}"
            MouseEnter="linkButton_MouseEnter" MouseLeave="linkButton_MouseLeave"/>

    I have defined a dependency property called TextDecoration of type TextDecorationCollection and when the event MouseEnter occurs I set the property to TextDecorations.Underline. It compiles OK but when I run it I receive an error

    Blend says that the "Member TextDecoration is not recognized or is not accessible". TextDecoration is defined like this:

     public TextDecorationCollection TextDecoration {
                get { return (TextDecorationCollection) GetValue(TextDecorationProperty); }
                set { SetValue(TextDecorationProperty, value); }
            }

            public static DependencyProperty TextDecorationProperty =
                DependencyProperty.Register("TextDecoration", typeof(TextDecorationCollection), typeof(LinkButton),
                                            new PropertyMetadata(new PropertyChangedCallback(LinkButton.OnTextDecorationPropertyChanged)));

            private static void OnTextDecorationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            }

    What could be the problem ??? 

    Thanks in advance

    Saturday, March 7, 2009 2:47 PM

Answers

  • I would suggest modifying the HyperlinkButton control's theme in Blend 2. (Or just using the HyperlinkButton, if you didn't know that existed.) That would be the easiest way to do it.
    Saturday, March 7, 2009 3:20 PM