WPF文字显示属性(转)

WPF文字显示属性

ProgressBar控件的重要属性: 
FontFamily——控件中显示文本的字体 
FontSize——控件中显示的字体的大小 
Foreground——控件中显示的文本的前景色 
Text——显示的文本的内容 
TextWrapping——控件中显示的文本的换行方式。 
   NoWrap——不自动换行,超出的部分被截断, 
   Wrap——自动换行,文本长度超出控件宽度时自动换行。 
Visibility——值为True时文本可见,值为False时文本不可见。

 <Canvas x:Name="LayoutRoot" Background="White">
        FontSize——字体大小
        Foreground——文本前景色
        <TextBlock Text="信息显示控件示例——TextBlock" Margin="10,5,0,0" FontSize="18" FontWeight="Bold" Foreground="#ffbe4d4d"/> <TextBlock Text="1、显示红色的文本" Foreground="Red" Canvas.Left="10" Canvas.Top="40"/> <TextBlock Text="2、显示带双引号&quot;TextBlock&quot;文本" Canvas.Left="10" Canvas.Top="60"/> FontStretch——字间距 <TextBlock Text="3、文本带下划线" TextDecorations="Underline" FontStretch="Normal" FontSize="16" Canvas.Left="10" Canvas.Top="80"/> TextAlignment——水平对齐方式 TextWrapping——是否自动换行 <TextBlock Text="4、多行文本显示,当文本的长度超过TextBlock控件的宽度将自动换行。" TextAlignment="Left" LineHeight="20" Width="200" TextWrapping="Wrap" Canvas.Left="10" Canvas.Top="110"/> <TextBlock Canvas.Left="10" Canvas.Top="160" FontStretch="UltraExpanded"> 5、不通过Text属性设置文本,直接在TextBlock容器中放置 </TextBlock> <TextBlock Canvas.Left="10" Canvas.Top="180" FontStretch="UltraCondensed"> 6、不通过Text属性设置文本,直接在TextBlock容器中放置 </TextBlock> </Canvas>
 

 

 

转载于:https://www.cnblogs.com/LiZhongZhongY/p/10870303.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以在 WPF 的 ComboBox 中使用 Placeholder 或 Watermark 来显示提示文字。以下是一些实现方法: 1. 使用自定义样式,在样式中添加一个 TextBlock 控件,当 ComboBox 中没有选中项时,显示提示文字。 2. 使用第三方库,如 MahApps.Metro,它提供了一个 Watermark 属性,可以在 ComboBox 中显示提示文字。 以下是一些样式代码示例: ```xml <!-- 使用样式实现 ComboBox 的 Placeholder --> <Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBox}"> <Grid> <ToggleButton x:Name="ToggleButton" Template="{DynamicResource ComboBoxToggleButton}" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"> </ToggleButton> <ContentPresenter x:Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="5, 0, 0, 0" VerticalAlignment="Center" HorizontalAlignment="Left" /> <TextBlock x:Name="Placeholder" Text="Enter text here" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5, 0, 0, 0" Foreground="Gray" Visibility="Collapsed"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" Value="{x:Null}"> <Setter Property="Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> <Popup x:Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide"> <Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"> <ScrollViewer Margin="4, 6, 4, 6" SnapsToDevicePixels="True"> <StackPanel IsItemsHost="True" /> </ScrollViewer> </Border> </Grid> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="ContentSite" Property="Opacity" Value="0.5" /> <Setter TargetName="Placeholder" Property="Opacity" Value="0.5" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- 使用 MahApps.Metro 实现 ComboBox 的 Watermark --> <ComboBox x:Name="MyComboBox" IsEditable="True" IsTextSearchEnabled="False" IsTextSearchCaseSensitive="False" Watermark="Enter text here" /> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值