Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-3349) Fix disable content of ToggleButton & Button when using circle style #3610

Merged
merged 2 commits into from
Sep 19, 2019

Conversation

mgnslndh
Copy link
Contributor

@mgnslndh mgnslndh commented Sep 19, 2019

Describe the changes you have made to improve this project

  • Added setter for the Foreground property to MahApps.Styles.ToggleButton.Circle when IsEnabled=False
  • Added setter for the Foreground property to MahApps.Styles.Button.Circle when IsEnabled=False
  • Updated demo with enabled/disabled version of MahApps.Styles.Button.Circle (current demo only display a custom derived style for Accent color)

Closed Issues

Closes #3349

@timunie
Copy link
Collaborator

timunie commented Sep 19, 2019

Hi @mgnslndh for other controls MahApps uses an opaque overlay over the button /control. I don't have a PC right now but I think I saw it at the
SquareButton. What do you think? I will show you the file as soon as my Internet is back. 😄

Happy coding
Tim

@mgnslndh
Copy link
Contributor Author

@timunie thanks for the feedback!

This was just a quick fix using the same solution as found on other button styles:

<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray2}" />
</Trigger>

<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Gray2}" />
</Trigger>

<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#ADADAD" />
</Trigger>

I'm not aware of an easy way of doing an overlay of an elliptical control with transparent background.

Using an overlay like for the default button style probably works well because it is rectangular and the whole content area is covered by the disabled state.

<Border x:Name="DisabledVisualElement"
Background="{DynamicResource MahApps.Brushes.Controls.Disabled}"
CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.CornerRadius), Mode=OneWay}"
IsHitTestVisible="False"
Opacity="0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

Not sure that is how the circle variant is supposed to look. Disabled state covering the whole circle. This is the expected result from the original issue:

Expected

Do you have any suggestions?

@punker76 punker76 added this to the 2.0.0 milestone Sep 19, 2019
@punker76 punker76 merged commit 9c721a4 into MahApps:develop Sep 19, 2019
@punker76
Copy link
Member

@mgnslndh your changes have been merged, thanks for your contribution 👍

I added 2 more samples to the demo which shows the workaround for disabled Buttons with custom Foreground (and respect the changes from GH-3121, GH-3101).

            <StackPanel Margin="{StaticResource ControlMargin}"
                        HorizontalAlignment="Center"
                        Orientation="Horizontal">
                <ToggleButton Width="48"
                              Height="48"
                              Margin="4"
                              Foreground="{DynamicResource MahApps.Brushes.Accent}"
                              Style="{DynamicResource MahApps.Styles.ToggleButton.Circle}">
                    <ToggleButton.ContentTemplate>
                        <DataTemplate>
                            <iconPacks:PackIconModern Width="20"
                                                      Height="20"
                                                      Kind="City" />
                        </DataTemplate>
                    </ToggleButton.ContentTemplate>
                </ToggleButton>
                <ToggleButton Width="48"
                              Height="48"
                              Margin="4"
                              Foreground="{DynamicResource MahApps.Brushes.Accent}"
                              IsEnabled="False"
                              Style="{DynamicResource MahApps.Styles.ToggleButton.Circle}">
                    <ToggleButton.ContentTemplate>
                        <DataTemplate>
                            <iconPacks:PackIconModern Width="20"
                                                      Height="20"
                                                      Kind="City" />
                        </DataTemplate>
                    </ToggleButton.ContentTemplate>
                </ToggleButton>
            </StackPanel>

2019-09-19_15h52_26

            <StackPanel Margin="{StaticResource ControlMargin}"
                        HorizontalAlignment="Center"
                        Orientation="Horizontal">
                <Button Width="48"
                        Height="48"
                        Margin="4"
                        Foreground="{DynamicResource MahApps.Brushes.Accent}"
                        Style="{StaticResource MahApps.Styles.Button.Circle}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <iconPacks:PackIconModern Width="20"
                                                      Height="20"
                                                      Kind="City" />
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
                <Button Width="48"
                        Height="48"
                        Margin="4"
                        Foreground="{DynamicResource MahApps.Brushes.Accent}"
                        IsEnabled="False"
                        Style="{StaticResource MahApps.Styles.Button.Circle}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <iconPacks:PackIconModern Width="20"
                                                      Height="20"
                                                      Kind="City" />
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
            </StackPanel>

2019-09-19_15h52_37

@mgnslndh
Copy link
Contributor Author

Nice @punker76! Moving to 2.0.0 release one issue at a time :)

@mgnslndh mgnslndh deleted the feature/GH-3349 branch September 19, 2019 15:06
@timunie
Copy link
Collaborator

timunie commented Sep 20, 2019

Hello @mgnslndh ,

just for information you can find my first idea below:
image

<Ellipse x:Name="PART_Overlay"
         Stroke="{DynamicResource MahApps.Brushes.White}"
         Fill="{DynamicResource MahApps.Brushes.White}"
         Opacity="0.8"
         Visibility="Collapsed"
         StrokeThickness="{Binding RelativeSource={x:Static RelativeSource.TemplatedParent}, Path=BorderThickness, Converter={StaticResource BorderThicknessToStrokeThicknessConverter}}" />

[...]

<Trigger Property="IsEnabled" Value="False">
    <Setter TargetName="PART_Overlay" Property="Visibility" Value="Visible" />
</Trigger>

I have to agree that your and @punker76 's solution looks much nicer! Thank you 👍

Happy coding
Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

ToggleButton IsEnable=false is not working.
3 participants