欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c# WPF 动态设置button的IsEnabled属性

程序员文章站 2022-03-07 11:06:18
...

XAML:

<DataGridTemplateColumn  Header="类型费用模板" Width="Auto" >
        <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                   <StackPanel Orientation="Horizontal">
                       <Label Content="{Binding busi_limit_str}" />
                       <Custom:MetroButton   Content="关联类型模板" Command="{Binding DataContext.ClickReletion_fee_assertacco1,RelativeSource={RelativeSource AncestorType=Custom:MetroDataGrid}}" Width="81" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
                       <Custom:MetroButton   Content="取消关联" IsEnabled="{Binding IsTypeEnable}" Command="{Binding DataContext.DeleteFeeTmplate1,RelativeSource={RelativeSource AncestorType=Custom:MetroDataGrid} }"  Width="81" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                    </StackPanel>
                </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

根据busi_limit_str是否为空,来确定取消关联是否可操作。

VM:

astAco.busi_config_str = getDictStr("secu_fee_tmplat_no", SecuFee.secu_code_fee_tmplat_no.ToString());
astAco.busi_limit_str = getDictStr("secu_fee_tmplat_no", SecuFee.secu_type_fee_tmplat_no.ToString());
astAco.IsCodeEnable = !string.IsNullOrWhiteSpace(astAco.busi_config_str);
astAco.IsTypeEnable = !string.IsNullOrWhiteSpace(astAco.busi_limit_str);

遍历每一个对象,对其IsCodeEnable进行赋值。这样就对每一个对象进行动态赋值了。