C# WPF工具提示文本对齐
我有以下C# WPF工具提示文本对齐,c#,wpf,tooltip,C#,Wpf,Tooltip,我有以下ListViewItem: <GridViewColumn Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}},
ListViewItem
:
<GridViewColumn Width="{Binding ActualWidth,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}},
Converter={StaticResource MathConverter}, ConverterParameter=(x/10)*1}">
<GridViewColumn.Header>
<GridViewColumnHeader Content=" Total Fees "
HorizontalContentAlignment="Right" />
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding GarnishmentTotals.TotalFees, StringFormat={}{0:c}}"
TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我对工具提示中的文本对齐有问题
文本似乎使用ListViewItems文本对齐方式(右)。我已尝试将以下属性添加到样式中,但没有任何更改:
<Setter Property="TootlTip.HorizontalAlignment" Value="Left" />
<Setter Property="TootlTip.HorizontalContentAlignment" Value="Left" />
<Setter Property="TootlTip.Width" Value="300" />
有没有办法增加工具提示的宽度,使文本不被包装,或者使工具提示的文本左对齐。由于工具提示是一个内容控件,您可以根据需要自定义其内容。考虑下面的例子:
<Grid>
<Button Content="Hi there!">
<Button.Style>
<Style TargetType="Button">
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip MaxWidth="100" HorizontalContentAlignment="Center">
<TextBlock Text="fsdfasdfasdfasdfasdfasdfadsfasdf fadsfadsf adfa fdasfasdfasdfa adfasd" TextAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap"/>
</ToolTip>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Grid>
您可以使用内容的属性(在本例中为TextBlock)来实现您想要的最终外观。我也遇到了同样的问题,经过一些挖掘(),我找到了解决方案。也许很晚了,但这对其他人有利
您需要做的是如下设置工具提示样式:
<Style TargetType="ToolTip">
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
<Style TargetType="ToolTip">
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>