鉴于我们通过样式使用工具提示,如何在 WPF 中的工具提示中换行文本

tra*_*ler 0 .net c# wpf xaml

<Style TargetType="{x:Type Label}">
 <Setter Property="ToolTip" Value="{Binding PropertyOne, 
  Converter={StaticResource SettingsToDescriptionConverter}}"/>                                                      
</Style>
Run Code Online (Sandbox Code Playgroud)

我在 ExtendedDataGrid 的 ElementStyle 中使用这种样式。

我已经尝试过这个-

<Setter Property="ToolTip.Style" Value="{StaticResource tooltipstyle}"/>
Run Code Online (Sandbox Code Playgroud)

但它给出了我们不能在样式中使用样式的错误。

任何帮助将不胜感激。

Ste*_*pUp 6

您可以在文件中声明Styleof并随时使用以下方法应用of :ToolTipApp.xamlStyleToolTipx:Key property

<Style TargetType="ToolTip" x:Key="fooToolTip">
        <Setter Property="MaxWidth" Value="20" />
        <!--OR-->
        <!--<Setter Property="MaxWidth" Value="{Binding Path=(lib:ToolTipProperties.MaxWidth)}" />-->
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <ContentPresenter Content="{TemplateBinding Content}">
                        <ContentPresenter.Resources>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="TextWrapping" Value="Wrap" />
                            </Style>
                        </ContentPresenter.Resources>
                    </ContentPresenter>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Run Code Online (Sandbox Code Playgroud)

你的例子:

<Label Content="For ToolTip">
    <Label.ToolTip>
        <ToolTip Style="{StaticResource fooTooltip}">
           <TextBlock>This is the Wrapped Tooltip</TextBlock>
        </ToolTip>
    </Label.ToolTip>
</Label>
Run Code Online (Sandbox Code Playgroud)