如何在禁用WPF圆形按钮时将其灰显?

时间:2017-10-10 11:19:13

标签: c# wpf

我希望整个底部变灰:
enter image description here

这是我的代码:

<Button Width="120" Cursor="Hand" 
            Name="btnPrintCard"
            Click="btnPrintCard_Click"
            Height="120" 
            HorizontalAlignment="Center"
                Style="{DynamicResource MetroCircleButtonStyle}">
    <Rectangle Width="80" Height="80" Fill="Green">
        <Rectangle.OpacityMask>
            <VisualBrush Stretch="Fill" Visual="{iconPacks:PackIconFontAwesome print}" />
        </Rectangle.OpacityMask>
    </Rectangle>
    <Button.ToolTip>
        <ToolTip>
            <StackPanel>
                <TextBlock FontWeight="Bold">Print</TextBlock>
                <TextBlock>Start printing card</TextBlock>
            </StackPanel>
        </ToolTip>
    </Button.ToolTip>
</Button>

*我已经找到了关于灰色按钮图像的主题,但在我的情况下,我使用的图标我不知道如何使它变得相同。

1 个答案:

答案 0 :(得分:3)

这应该有效:

public static void main(String[] args) { 
    //main function

    String str = "hello My name is"; 
    //string one
    String str2 = "viral";  
    //string two

    String commonChars = "";

    //creating a string of all common chars
    for (int i = 0; i < str.length(); i++) {
        for (int j = 0; j < str2.length(); j++) {
            if (str.charAt(i) == str2.charAt(j)) {

                commonChars += str.charAt(i);
            }
        }
    }


    //replace common chars in str and str2 with a blank 
    for(int i = 0; i < commonChars.length(); i ++)
    {
        String charToRemove = commonChars.charAt(i)+"";//change char to string
        str = str.replace(charToRemove, "");
        str2 = str2.replace(charToRemove, "");

    }

    String s3= str+str2;

    System.out.println("the string after removing common character  and concatenation is " + s3);

}

确保从Rectangle中删除<Rectangle Width="80" Height="80"> <Rectangle.OpacityMask> <VisualBrush Stretch="Fill" Visual="{iconPacks:PackIconFontAwesome print}" /> </Rectangle.OpacityMask> <Rectangle.Style> <Style TargetType="Rectangle"> <Setter Property="Fill" Value="Green" /> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Fill" Value="Gray" /> </Trigger> </Style.Triggers> </Style> </Rectangle.Style> </Rectangle> ,因为这会覆盖样式中的颜色集。

由于Fill="Green" inhertis 向下移动VisualTree,只要它的父级(或任何祖先,如按钮)被禁用,矩形IsEnabled将为IsEnabled。< / p>