Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't change the fontsize on Listview items or column headers

    <ListView x:Name="lstProductionOrders">
         <ListView.View>
              <GridView>
                   <GridViewColumn Header="Production Order:"/>
                        ...

I've set the fontsize on the grid, using textelement, I've set it on the listview, the columnheader, through styles, through styles using BasedOn. I even put in a brand new test window that had no other code in it but the default code and a listview created the same way above. Using all of the above, the font changes in design-time but not in run-time.

I've only got about 6 months of WPF/XAML experience, so I may be looking for the wrong thing. Is there some kind of global setting for fontsize or anything anyone can think of that would be causing this to be overridden.

For the record, I with the test window, there are no base classes.

----------EDIT----------

This was the source of the problem in App. xaml

<Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Times New Roman"/>
        <Setter Property="FontSize" Value="20"/>
</Style>
like image 914
Yatrix Avatar asked Dec 09 '11 14:12

Yatrix


3 Answers

This sounds a lot like you have an implicit style for GridViewColumn that overwrites changes you made locally.

At design time, that implicit style is not taken into account (could be for various reasons), but at runtime it is, and you get that strange behavior.

I would start by looking into App.xaml's Resources section, then move upwards until I reach the control I care about.

Addition: implicit styles:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock">
         <Setter Property="FontSize" Value="40" /> <!-- stupid value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

If you ever want to define an implicit style locally without overwriting another implicit style set higher up the chain, you can do this:

<UserControl>
   <UserControl.Resources>
      <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
         <Setter Property="FontSize" Value="60" /> <!-- ridiculous value, just to make it obvious it changed something =) -->
      </Style>
   </UserControl.Resources>
</UserControl>

It will inherit the implicit style in place and add changes for the local UserControl.

like image 145
Louis Kottmann Avatar answered Nov 04 '22 11:11

Louis Kottmann


For me the following works for both header and items:

<ListView ItemsSource="{Binding Source={StaticResource Items}}"
          TextElement.FontSize="16">
    <!-- ... -->

No idea what could be wrong in your case though...

like image 40
H.B. Avatar answered Nov 04 '22 10:11

H.B.


if you want only set the header size, then try this solution or use @H.B. solution

<ListView x:Name="lstProductionOrders" >
    <ListView.View>
        <GridView>
            <GridViewColumn>
                <GridViewColumnHeader TextElement.FontSize="16">Production Order:/GridViewColumnHeader>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

enter image description here

hope this helps

like image 28
punker76 Avatar answered Nov 04 '22 11:11

punker76