[英]How to style TextBox Header?
I am using a TextBox
like this: 我正在使用这样的TextBox
:
<TextBox x:Name="TxtName" IsEnabled="False" Header="Textbox header" IsReadOnly="True" TextWrapping="Wrap" Text="{Binding Name,Mode=TwoWay}" Style="{StaticResource MyTextBoxStyle}" />
I would like to be able to style (ie setting the font) the Header
of the TextBox
in a ResourceDictionary
. 我希望能够在ResourceDictionary
中设置TextBox
Header
的样式(即设置字体)。 When I set the FontFamily
of the TextBox
it also affect the header, but I would like to set two different font styles for the text inside the TextBox
and the text in the Header
. 当我设置TextBox
的FontFamily
时,它也会影响标题,但是我想为TextBox
内部的TextBox
和Header
的文本设置两种不同的字体样式。
This is my style for the TextBox
: 这是我的TextBox
风格:
<Style x:Key="MyTextBoxStyle" TargetType="TextBox">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontFamily" Value="Comic Sans MS" />
</Style>
How can I do this? 我怎样才能做到这一点?
Try This 尝试这个
<TextBox Height="70" Width="200" Text="Text" Foreground="Green" FontFamily="Tahoma">
<TextBox.Header>
<TextBlock Text="Header" Foreground="red" FontFamily="Times New Roman"></TextBlock>
</TextBox.Header>
</TextBox>
Update 更新
<Page.Resources>
<Style TargetType="TextBox">
<Setter Property="Height" Value="70"></Setter>
<Setter Property="Width" Value="200"></Setter>
<Setter Property="Text" Value="Text"></Setter>
<Setter Property="FontFamily" Value="Tahoma"></Setter>
<Setter Property="Foreground" Value="Green"></Setter>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Foreground="Red" Text="{Binding}" FontFamily="Times New Roman"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<TextBox Header="Header" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.