【问题标题】:How to style TextBox Header?如何设置文本框标题的样式?
【发布时间】:2015-03-19 08:24:22
【问题描述】:

我正在使用这样的TextBox

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

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

这是我对TextBox的风格:

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

我该怎么做?

【问题讨论】:

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


    【解决方案1】:

    试试这个

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

    【讨论】:

    • 但是如何在我的 TextBox 的样式中做到这一点?我不想为我拥有的每个 TextBox 设置多次。
    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 2012-07-12
    • 2020-07-17
    相关资源
    最近更新 更多