WPF 纵向文字显示

WPF 纵向文字显示

几种效果:
在这里插入图片描述
代码:

<Grid>
        <TextBlock Width="100" Height="40" FontSize="30" Text="大家好" Margin="100 0 0 0">
            <TextBlock.LayoutTransform>
                <RotateTransform Angle="270"></RotateTransform>
            </TextBlock.LayoutTransform>
        </TextBlock>

        <Label x:Name="label"  Content="你&#x000A;好"  FontSize="20"/>

        <TextBlock TextWrapping="Wrap" Padding="0" LineHeight="0.1" FontSize="20" Width="{Binding RelativeSource={RelativeSource Self},Path=FontSize}" Text="很高兴"/>
    </Grid>

或者:

<TextBlock FontSize="30" Text="天&#x0a;天&#x0a;好&#x0a;心&#x0a;情"></TextBlock>

或者:
Preserve能保留xaml中的空格

<TextBlock xml:space="preserve">
第一行
第二行
</TextBlock>

或者:

<TextBlock Text="{Binding StringFormat='第一行{0}第二行{0}第三行',
                          Source={x:Static s:Environment.NewLine}}" />
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值