Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Please look at this sample.

I have a silverlight project. it has a style file that merged with app.xaml

My global style :

XML
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Tahoma" />
    </Style>   
</ResourceDictionary>




I Merged it to app.xaml :

XML
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="SilverlightApplication1.App"
             >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>



It has a MainPage :

XML
<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" removed="White">
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="41,51,0,0" Name="textBlock1" Text="ABC" VerticalAlignment="Top" />
        <Button  Height="23" HorizontalAlignment="Left" Margin="41,80,0,0" Name="button1" VerticalAlignment="Top" Width="75" >
            <Button.Template>
                <ControlTemplate>
                    <Border>
                        <TextBlock Text="ABC"  />
                    </Border>
                </ControlTemplate>
            </Button.Template>
        </Button>
       
    </Grid>
</UserControl>


in My MianPage I have a textBlock and a button with Template.
My global style apply on the TextBlock but do not apply on textblock that is
in the DateTemplete for button.

How can I solve this problem that global style apply on the element on DataTemplte ?

Thanls a lot
Posted
Comments
Kenneth Haugland 21-Jul-12 9:55am    
Perhaps is a Name="" issue?

1 solution

Sorry, I thionk I got in now:
http://stackoverflow.com/questions/1786031/applying-a-fontfamily-to-all-controls-in-silverlight-4-beta[^]

And this code would make them equal:
HTML
<Style TargetType="Button">
            <Setter Property="FontFamily" Value="Webdings"   />
        </Style>
           <Style TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Webdings"   />
        </Style>
 
Share this answer
 
v2
Comments
mohammadghaderian.bp 21-Jul-12 10:50am    
I know how to set global style. I want to set my global style in datatemplate elements too
Kenneth Haugland 21-Jul-12 13:57pm    
You cant, if you read the link it explains...
Kenneth Haugland 21-Jul-12 13:49pm    
Then you have to set an XKey in you style, and spesificaly set the style of the textbox indide the partent button control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900