簡體   English   中英

如何設置文本框標題的樣式?

[英]How to style TextBox Header?

我正在使用這樣的TextBox

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

我希望能夠在ResourceDictionary中設置TextBox Header的樣式(即設置字體)。 當我設置TextBoxFontFamily時,它也會影響標題,但是我想為TextBox內部的TextBoxHeader的文本設置兩種不同的字體樣式。

這是我的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" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM