t9mike
t9mike

Reputation: 1626

Inside a WPF UserControl, set FontSize on child control to the UserControl's FontSize

I'm trying to set the FontSize -- amoung other things -- on some control's within a UserControl to the UserControl-level FontSize. This is not working:

<UserControl x:Class="TestWpfApplication1.Scratch.UserControlFontSizeProp"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
   <Grid>
       <TextBlock 
        FontSize="{Binding RelativeSource={RelativeSource self},Path=FontSize}">
           Text
       </TextBlock>
   </Grid>
</UserControl>

What am I doing wrong? Thanks.

Upvotes: 3

Views: 3949

Answers (2)

UJK
UJK

Reputation: 97

I use

FontSize="{Binding Parent.Parent.FontSize, RelativeSource={RelativeSource Self}}"

Upvotes: 0

Faaiz Khan
Faaiz Khan

Reputation: 332

Think this should work..

<TextBlock FontSize="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FontSize}" /> 

Upvotes: 7

Related Questions