wade
wade

Reputation: 49

Style referenced in generic.xaml not being applied

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

Upvotes: 2

Views: 1384

Answers (1)

Tejas Sharma
Tejas Sharma

Reputation: 3440

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.

Upvotes: 1

Related Questions