I'm trying to create a "Vector Path" based Button Glyph that exactly matches the height of the default height of the Button Control font. So that its button fits onto the same toolbar with the same height automatically. However, when I do this the Button with normal text set as content has a larger overall height then the one with the "Vector Path" set as the content. Here's my code below. How can I get the "Vector Path" Content button to have the same height as the "string" content button automatically based on button default settings? Am I missing a padding setting in the "Vector Path" Version that needs to be accounted for?
// C# / UWP
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Data;
namespace GridNineExperiment
{
// "String" Content Button
public class Button1 : Button
{
public Button1()
{
Content = "Hello";
}
}
// "Path Vector" Content Button
public class HamburgerButton : Button
{
public HamburgerButton()
{
// Default Font Height of Button
double H = (double)Button.FontSizeProperty.GetMetadata(typeof(double)).DefaultValue;
double A = H / 5;
GeometryCollection DataHamburger = new GeometryCollection
{
new RectangleGeometry {Rect = new Rect{X = 0, Y = 0*A, Width = 20, Height = A/2 }},
new RectangleGeometry {Rect = new Rect{X = 0, Y = 2*A, Width = 20, Height = A/2 }},
new RectangleGeometry {Rect = new Rect{X = 0, Y = 4*A, Width = 20, Height = A/2 }},
};
Path PathHamburger = new Path
{
Fill = new SolidColorBrush(Colors.Black),
Stroke = new SolidColorBrush(Colors.Black),
StrokeThickness = 1.0,
Data = new GeometryGroup { Children = DataHamburger }
};
Content = PathHamburger;
}
}
}
<!-- This XAML demonstrates the button heights don't have
the same height despite setting the Vector Path
height to 11 pixels, the same as the Text of String based Button-->
<Page
x:Class="GridNineExperiment.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GridNineExperiment"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<local:Button1 Grid.Column="0" Grid.Row="0" Content="Hello"/>
<local:HamburgerButton Grid.Column="1" Grid.Row="0"/>
</Grid>
</Page>