<ItemsControl x:Class="HDSProject.Control.CustomFont" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HDSProject.Control" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" x:Name="itemCtrl" ItemsSource="{Binding Path=Title2, RelativeSource={RelativeSource Mode=Self}}" FontSize="20" Foreground="Teal" > <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Border Margin="{Binding Path=CharacterSpacing, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}"> <TextBlock Text="{Binding}" /> <Border.Style> <Style TargetType="Border"> <Setter Property="BorderThickness" Value="0"/> <Style.Triggers> <DataTrigger Binding="{Binding ShowUnderline, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}" Value="True"> <Setter Property="BorderThickness" Value="0 0 0 1"/> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <Border.BorderBrush> <SolidColorBrush Color="{Binding Foreground.Color, ElementName=itemCtrl}" /> </Border.BorderBrush> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>我希望输入的Title2可以换行,且可以设置行间距该怎么做
时间: 2023-07-19 14:25:12 浏览: 184
gong-wpf-dragdrop:GongSolutions.WPF.DragDrop库是WPF的拖放框架
您可以将StackPanel替换为一个WrapPanel,这样就可以实现Title2的换行了。而要设置行间距,您可以在WrapPanel中添加一个Margin属性,来实现行间距的设置。具体的修改代码如下:
```
<ItemsControl x:Class="HDSProject.Control.CustomFont"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HDSProject.Control"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
x:Name="itemCtrl"
ItemsSource="{Binding Path=Title2, RelativeSource={RelativeSource Mode=Self}}"
FontSize="20" Foreground="Teal">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Margin="0 10 0 0"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="{Binding Path=CharacterSpacing, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}">
<TextBlock Text="{Binding}" />
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ShowUnderline, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}" Value="True">
<Setter Property="BorderThickness" Value="0 0 0 1"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Border.BorderBrush>
<SolidColorBrush Color="{Binding Foreground.Color, ElementName=itemCtrl}" />
</Border.BorderBrush>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
```
在WrapPanel中加入了Margin属性,实现了行间距的设置。
阅读全文