【问题标题】:How to enable/disable a Button depending on the selection's type in WPF?如何根据 WPF 中的选择类型启用/禁用按钮?
【发布时间】:2012-05-08 10:16:30
【问题描述】:

我想根据当前选择的类型触发按钮的启用状态。

例如我有一个显示父母和他们的孩子的树视图。如果选择在“父”项上,则启用按钮“btnShowParentData”。 我是通过 ValueConvertion 完成的:

<Button name="btnShowParentData" IsEnabled="{Binding ElementName=tree, Path=SelectedValue, Converter={StaticResource ParentSelectedConv}}" />

我寻找一种更优雅的方式。我不想为每种选择类型创建一个 ConverterClass。

【问题讨论】:

    标签: wpf button treeview isenabled


    【解决方案1】:

    我不想为每种选择类型创建一个 ConverterClass。

    您可以在转换器上使用属性来对其进行参数化。

    【讨论】:

    • 用你的方法:参数是什么类型的?与 typeof(ParentClass).Name 进行比较的简单字符串?
    • 将其设为Type 并直接比较,在XAML 中您可以使用{x:Type ns:Class} 轻松获得typeof(Class)。 (如果属性是Type 类型,你甚至不需要x:Type,它会自动从字符串转换)
    猜你喜欢
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    相关资源
    最近更新 更多