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

"VisualButton" That makes working with the XAML icons easier #2003

Closed
bloritsch opened this issue Jun 25, 2015 · 0 comments
Closed

"VisualButton" That makes working with the XAML icons easier #2003

bloritsch opened this issue Jun 25, 2015 · 0 comments

Comments

@bloritsch
Copy link

Trying to get a button that uses the Mahapps.Metro.Resources icons looking right is currently a major pain. The problem is that the Rectangle that hosts the button doesn't resize and place the icon properly. The following is not only a lot to remember to get right each time, it only works if the button is large enough (18 DPU or bigger).

<Button x:Name="mybutton" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
    <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                      Fill="{Binding ElementName=mybutton, Path=Foreground}">
         <Rectangle.OpacityMask>
              <VisualBrush Visual="{StaticResource appbar_magnify_plus}" Stretch="Fill"/>
         </Rectangle.OpacityMask>
    </Rectangle>
</Button>

The only other way to make sure that the icon is sized appropriately is to set it explicitly. If you forget the HorizontalAlignment and VerticalAlignment on the Rectangle, the icon will always be 0,0 unless you set the height and width explicitly.

I'd like to simplify it a bit and just use a Controls:MetroButton or Controls:VisualButton:

  • Visual = the {StaticResource appbar_magnify_plus}
  • Style = enum ButtonStyle { Default, Square, Circle } (applies the appropriate style)

Placing that visual in the button is rather a pain, particularly if you want to have any sort of responsive UI where buttons scale in size depending on how much screen real-estate you have.

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

No branches or pull requests

1 participant