Changing Datagrid font in Silverlight 4 Windows Theme RRS feed

  • Question

  • Hello,

    i'm new to Silverlight. Especially using the Themes (Cosmopolitan, Windows, JetPack).

    I decided to realize a little project in Silverlight with the Windows Theme cause it fits the optical requirements best.

    Just the fonts for the datagrid should be others.

    I tried to change them in the assets (sdkstyles.xaml) but nothing happens.

    So the question from the subject:

    Where can i customize the font(family) for the datagrid? Embarassed



    Friday, October 28, 2011 1:39 PM

All replies

  • Hi

    Even when using theme you can still modify Font afterwards if you wish.

    In the following example I used an ExpressionDarkTheme from the Silverlight Toolkit, which is applied to everything included in the Grid...
    now if I want to modify let's say each Column header or content style of a datagrid, I can simply use a similar

       <Style x:Key="SomeDataGridHeaderStyle"
              <Setter Property="FontSize"
                      Value="14" />
              <Setter Property="FontFamily"
                      Value="Courier New" />
              <Setter Property="FontWeight"
                      Value="Bold" />
              <Setter Property="Foreground"
                       Value="Red" />    
       <Style x:Key="SomeDataGridContentStyle"
              <Setter Property="FontSize"
                      Value="14" />
              <Setter Property="FontFamily"
                      Value="Courier New" />
              <Setter Property="FontWeight"
                      Value="Bold" />
              <Setter Property="Foreground"
                       Value="Red" />    
    <Grid x:Name="LayoutGrid>
    <sdk:DataGrid x:Name="dg" Width="350" Height="350" AutoGeneratedColumns="False">
          <sdk:DataGridTemplateColumn Width="Auto" Header="Name" HeaderStyle="{StaticResource SomeDataGridHeaderStyle}">
           <TextBlock Text="{Binding Name} Style={StaticResource SomeDataGridContentStyle}/>

    Hope this helps

    If this answers your question, please Mark as an answer. Thank you. 

    Friday, October 28, 2011 3:21 PM
  • Hi

    thanks for your answer!!!

    Just a little bit embarrasing ;-). I didn't see that possibility. Unfortunately i cant try it at the moment but i'll try as soon as possible and i'm convinced that this is working.

    But for future projects i'd like to put in an own .....style.xaml, so that there will be the posibility to change the design just by replacing the ...style.xaml or the path to it in app.xaml (or something like that).



    Friday, October 28, 2011 3:55 PM
  • Hey please don't feel embarassed at all.
    I always believed there ain't nothing wrong in asking the right question ;)

    Not Bene: I put the style under the UserControl.Resources on the same .xaml for this sample purpose
    but please feel free to use any specific  style.xaml, generic.xaml, or app.xaml options
    you'll find more convenient ;)

    Friday, October 28, 2011 4:26 PM
  • If you want all the DataGrids in your app to automatically use this style, you can define a implicit style (a Style without key), put it in under Application.Resources either by define the style in the App.Xaml file or in a separate resources file to be included in the App.Xaml as one of the MergedDictionaries:

    Put following style in a DataGridStyle.xaml file under your application Assets folder:


      xmlns:x="http://schemas.micro soft.com/winfx/2006/xaml"

       xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  >

    <Style TargetType="data:DataGrid">
                <Setter Property="FontFamily" Value="Your Font Name"/>






                    <ResourceDictionary Source="Assets/DataGridStyle.xaml"/> 

    Friday, October 28, 2011 5:05 PM
  • HI everybody!

    thx for all answers. They're working. They mostly fit my needs...


    Just one more (and last) question:

    Is there a (simple) possibility to turn of the "visual effects" in the presentation of a DataGridCell (Just like the presentation of a 'normal' html page including <font='myFont'>text to display</font> without any shadowing or fading) ?

    Thanks for any answer!

    Monday, October 31, 2011 7:56 PM