无法在样式中设置工具提示
我搜索并发现我无法直接在 setter.value 中设置工具提示(在 style.xaml 文件中)。不过我可以使用静态资源来设置工具提示。
我的问题是,由于我需要为工具提示提供动态文本,因此我无法使用静态资源。我该怎么做呢?
这是我的例子。
<Style x:Key="ErrorStyleRadius" TargetType="{x:Type FrameworkElement}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding (Validation.HasError), RelativeSource={RelativeSource Mode=Self}}" Value="True"/>
<Condition Binding="{Binding (Validation.Errors), RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsError}}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip>
<Label Content="{Binding somePropertyHere}"/>
</ToolTip>
</Setter.Value>
</Setter>
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorControlTemplateRadiusError}"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding (Validation.HasError), RelativeSource={RelativeSource Mode=Self}}" Value="True"/>
<Condition Binding="{Binding (Validation.Errors), RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsWarning}}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource ValMsg}}"/>
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorControlTemplateRadiusWarning}"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
对于使用,我可以用作
<textbox style={staticresource ErrorStyleRadius} text={bind name, validationOnDataError=true}/>
I searched and find out I can't set the tooltip in setter.value directly (in a style.xaml file). However I can use static resource to set the tooltip.
My question is, since I need to supply dynamic text for the tooltip, I can't use static resource. How should I do that?
here is my example.
<Style x:Key="ErrorStyleRadius" TargetType="{x:Type FrameworkElement}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding (Validation.HasError), RelativeSource={RelativeSource Mode=Self}}" Value="True"/>
<Condition Binding="{Binding (Validation.Errors), RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsError}}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip>
<Label Content="{Binding somePropertyHere}"/>
</ToolTip>
</Setter.Value>
</Setter>
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorControlTemplateRadiusError}"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding (Validation.HasError), RelativeSource={RelativeSource Mode=Self}}" Value="True"/>
<Condition Binding="{Binding (Validation.Errors), RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsWarning}}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource ValMsg}}"/>
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorControlTemplateRadiusWarning}"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
for usage, i can use as
<textbox style={staticresource ErrorStyleRadius} text={bind name, validationOnDataError=true}/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不试试这个 -
您可以在 StaticResource 中给出属性名称。它将动态更新工具提示。
Why don't you try this -
You can give the property name in StaticResource. It will update the tooltip dynamically.
如果您想将文本设置为 Validation.Error ,您也可以从您的样式中设置工具提示,如下所示 -
Also you can set the tooltip from your style if you want to set the text to Validation.Error like this -