c# - 如何设置文本框标题的样式?

标签 c# xaml windows-store-apps winrt-xaml windows-8.1

我正在使用这样的 TextBox:

<TextBox x:Name="TxtName" IsEnabled="False" Header="Textbox header" IsReadOnly="True" TextWrapping="Wrap"  Text="{Binding Name,Mode=TwoWay}" Style="{StaticResource MyTextBoxStyle}" />

我希望能够在 ResourceDictionary 中为 TextBoxHeader 设置样式(即设置字体)。当我设置 TextBoxFontFamily 时,它也会影响页眉,但我想为 TextBox 中的文本设置两种不同的字体样式> 和 Header 中的文本。

这是我的 TextBox 样式:

<Style x:Key="MyTextBoxStyle" TargetType="TextBox">
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="FontFamily" Value="Comic Sans MS" />
</Style>

我该怎么做?

最佳答案

试试这个

     <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>

更新

<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" />

关于c# - 如何设置文本框标题的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29139865/

相关文章:

c# - 派生类对象在内存中是什么样子的?

c# - 最后:是否保证在任何情况下都会被调用

c# - GDI+画线算法

c# - ASP :Button CSS :after Selector (or :before)

c# - 媒体引擎错误,在本地机器上听不到声音

wpf - 图表绘图点 - 在 OxyPlot 中显示工具提示

xaml - ResourceLoader 在 ViewModel 中返​​回错误的语言

c# - Silverlight:当我调用 NavigationService.Navigate 时布局发生变化

windows-store-apps - 在 Windows 8.1 中生成应用程序包有什么作用?

c# - 如何更改 xaml 中定义的资源的值?