2

I have this style in Generic.xaml

<Style x:Key="WhiteHyperlink" TargetType="Hyperlink">
    <Setter Property="Foreground" Value="White" />
</Style>

I have this line in the resource dictionary

<Style TargetType="{x:Type Hyperlink}" BasedOn="{StaticResource WhiteHyperlink}" />

And I want to apply it to this:

<Textblock Grid.Colum="2" >
    <Hyperlink Command="{StaticResource ExecuteMailAction}" CommandParameter="{Binding Path=MailboxID}">
        <TextBlock Text="{Binding Path=MailboxName}" />
    </Hyperlink>
</Textblock>

But the formatting is not being applied. What am I missing?

Thanks

wade
  • 49
  • 9

1 Answers1

1

I looked up Generic.xaml and it appears that the styles in Generic.xaml only get applied if the control which is being styled does not a default style which is theme dependent. ( What is so special about Generic.xaml? ) I'm guessing that Hyperlink has a default style dependent on the OS' theme which is why your style is not getting pulled from Generic.xaml. I'd recommend not using Generic.xaml to store your styles but rather creating a separate file to store all your styles (MyStyles.xaml or something like that). Then simply use ResourceDictionarys to get the style from that file.

Community
  • 1
  • 1
Tejas Sharma
  • 3,420
  • 22
  • 35
  • Your code is styling the text box, I'm trying to style the hyperlink. – wade Oct 12 '12 at 20:57
  • yes I understand that, but the basic logic is still the same. If a style gets applied to one control, it will get applied to another. Like I mentioned in my answer, the reason you are not seeing any changes is probably because the property is being set elsewhere. – Tejas Sharma Oct 12 '12 at 21:00
  • Also, shouldn't the `Hyperlink` element be a child of the `TextBlock` element and not the other way round? – Tejas Sharma Oct 12 '12 at 21:05
  • Edited code so that I'm styling a hyperlink, still works just fine. – Tejas Sharma Oct 12 '12 at 21:08
  • I changed your code to the following and it worked: Maybe your binding is incorrect? Look in the output window for binding errors. – Tejas Sharma Oct 12 '12 at 21:11
  • The styling works fine as long as it's in the same file as what I'm styling, where I seem to be getting into problems is when I move the style to a resource file. – wade Oct 12 '12 at 21:11
  • Yes, that is how I have it, I didn't include the extra Textblock tag. Sorry – wade Oct 12 '12 at 21:15