C# 在WPF UserControl中,将子控件上的FontSize设置为UserControl';s字体大小
我试图将UserControl中某个控件的FontSize(以及其他内容)设置为UserControl级别的FontSize。这不起作用:C# 在WPF UserControl中,将子控件上的FontSize设置为UserControl';s字体大小,c#,wpf,wpf-controls,C#,Wpf,Wpf Controls,我试图将UserControl中某个控件的FontSize(以及其他内容)设置为UserControl级别的FontSize。这不起作用: <UserControl x:Class="TestWpfApplication1.Scratch.UserControlFontSizeProp" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sc
<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>
正文
我做错了什么?谢谢。我想这应该行得通
<TextBlock FontSize="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=FontSize}" />
FontSize属性继承自可视树中的父元素。没有必要设定那个。另外,relativesourceself
指向TextBlock
,而不是UserControl
啊,我现在看到我的问题了。我选择了我的一种全局样式。这将覆盖我的全局样式。谢谢