【问题标题】:How to disable RadComboxBox only when its source is Empty and display a tooltip message如何仅在源为空时禁用 RadComboxBox 并显示工具提示消息
【发布时间】:2015-11-30 05:00:13
【问题描述】:

我必须在 GridViewDataColumn 中添加一个 RadComboBox。此组合框必须填充一个列表。我必须设置一个条件,如果列表为空,则应禁用此组合框,并且必须显示“无可用设置”的工具提示消息。

以下是我在 xaml 文件中的代码:

<telerikGrid:GridViewDataColumn HeaderCellStyle="{StaticResource HeaderStyle}"
                                                            Width="Auto"
                                                            Header="Decrypt" x:Name="colDecrypt">
    <telerikGrid:GridViewColumn.CellStyle>
        <Style TargetType="telerikGridView:GridViewCell">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerikGridView:GridViewCell">
                        <Border>
                            <telerik:RadComboBox x:Name="cbxDecrypt" Margin="5,1,5,1" Width="Auto"
                                            ItemsSource="{Binding Mode=OneWay, Source={StaticResource Parameter}, Path=EquivalenceNames}"
                                            SelectionChanged="cbxDecrypt_SelectionChanged" SelectedItem="{Binding SelectedEquivalence}"
                                            ToolTipService.ToolTip="No Decrypt Settings available"
                                            />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </telerikGrid:GridViewColumn.CellStyle>
</telerikGrid:GridViewDataColumn>

任何帮助将不胜感激。

【问题讨论】:

    标签: c# wpf xaml telerik


    【解决方案1】:

    我创建了一个简单的例子: 我们将使用 ObservableCollection 作为 DataContext:

    DataContext = new ObservableCollection<string>();
    

    默认情况下工具提示不会显示在禁用控件上,因此我们需要使用 ToolTipService.ShowOnDisabled 属性。

    <telerik:RadComboBox ToolTipService.ShowOnDisabled="True" ItemsSource="{Binding}">
        <telerik:RadComboBox.Style>
            <Style TargetType="telerik:RadComboBox">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Count, Mode=OneWay}" Value="0">
                        <Setter Property="IsEnabled" Value="False"/>
                        <Setter Property="ToolTip" Value="No Decrypt Settings available"/>
                    </DataTrigger>    
                </Style.Triggers>
            </Style>
        </telerik:RadComboBox.Style>
    </telerik:RadComboBox>
    

    如果您使用 Noxaml 版本的 Telerik 库,那么您需要一些修复,例如:

    <Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource RadComboBoxStyle}">
        <!--...-->
    </Style>
    

    【讨论】:

    • 我在我的 Silver light 应用程序中使用它。当我使用 ToolTipService.ShowOnDisabled 或 Style.Triggers 时,它会给出错误“在类型 ToolTipService 中找不到可附加属性 'ShowOnDisabled'”。有什么具体原因吗?抱歉,我是新手。
    • 是的,在 Silverlight 中我们不能使用这样的属性。但我们有解决方案 - codeproject.com/Tips/123961/…
    • 是的,它有效。您能否建议我如何禁用源为空的项目?
    • 源内容为空?一些具有适当条件的 DataTrigger。
    • 是的,但 Silver light 应用程序也不支持数据触发器。无论如何,非常感谢你的帮助:)
    【解决方案2】:

    我发现以下链接非常有用,可以轻松解决我的问题:

    1. 对于在 List 为空时禁用项目的第一个问题,此处提供了一个非常简单的解决方案:

    ComboBox IsEnabled Binding Question in Silverlight Xaml

    1. 对于显示工具提示消息的第二个问题,此处提供了一个非常好的解决方案: http://dotplusnet.blogspot.in/2010/09/workaround-for-showing-tooltip-for.html

    使用 Border Background="Transparent" 可以解决这个问题。

    【讨论】:

      猜你喜欢
      • 2014-09-28
      • 1970-01-01
      • 2023-04-09
      • 2023-01-22
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      相关资源
      最近更新 更多