Button的IsEnabled属性取决于Command属性?

时间:2013-11-08 15:36:41

标签: wpf button isenabled

我对Button的以下行为感到惊讶。

我为button + image创建了一个usercontrol。

<UserControl x:Name="root">
    <Button Command="{Binding ClickCommand, ElementName=root}" Click="Button_Click">
        <StackPanel>
            <Image Source="{Binding ImageSource, ElementName=root, Mode=OneWay}"
                   Stretch="None" />
            <TextBlock Padding="4,0"
                       Text="{Binding Caption, ElementName=root, Mode=OneWay}" />
        </StackPanel>
    </Button>
</UserControl>

ClickEventClickCommandProperty作为RoutedEvent和DependencyProperty在代码隐藏中。

它按预期工作,但我不明白为什么当我没有将xaml中的ClickCommand设置为空字符串时,无法启用UserControl

<c:ImageButton Caption="Refresh" Click="refresh_Click" x:Name=btnRefresh
               ClickCommand="" ImageSource="{StaticResource refresh}" />

因此,如果没有ClickCommand="",则代码btnRefresh.IsEnabled = true;无效 另外:IsEnabledChanged事件由.IsEnabled = true;调用,而不是再次将其设置为false?奥秘。

0 个答案:

没有答案
相关问题