I'm trying to extend button class with a ButtonType like this:
public class MyButton : Button
{
public MyButton()
{
}
public string ButtonType
{
get { return (string)GetValue(ButtonTypeProperty); }
set
{SetValue(ButtonTypeProperty, value);}
}
// Using a DependencyProperty as the backing store for ButtonType. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ButtonTypeProperty =
DependencyProperty.Register("ButtonType", typeof(string), typeof(MyButton), new PropertyMetadata(0));
}
My button template:
<ControlTemplate TargetType="controls:RMButton">
<Grid x:Name="BtnInnerGrid" RenderTransformOrigin="0.5,0.5" BorderBrush="{ThemeResource RMWhiteSmoke}" BorderThickness="2" Background="{ThemeResource RMTranslucentBlackBrush}" CornerRadius="20" Padding="0">
<Grid.RenderTransform>
<CompositeTransform ScaleX="1" ScaleY="1" />
</Grid.RenderTransform>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.200000">
<VisualTransition.GeneratedEasingFunction>
<CubicEase EasingMode="EaseOut" />
</VisualTransition.GeneratedEasingFunction>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="BtnInnerGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="BtnInnerGrid.(UIElement.Opacity)" Value="0.7" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Target="BtnInnerGrid.(UIElement.Opacity)" Value="0.7" />
<Setter Target="BtnInnerGrid.(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Value="0.9" />
<Setter Target="BtnInnerGrid.(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Value="0.9" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="BtnInnerGrid.(UIElement.Opacity)" Value="0.3" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition x:Name="BtnGridTopRow" />
<RowDefinition x:Name="BtnGridBottomRow" />
</Grid.RowDefinitions>
<RelativePanel x:Name="TopRowRelativePanel" Grid.Column="0" Grid.Row="0">
<Viewbox x:Name="FontIconViewBox" Visibility="Collapsed">
<FontIcon x:Name="BtnFontIcon" FontFamily="Segoe MDL2 Assets" Glyph="" />
</Viewbox>
<Viewbox x:Name="ImageViewBox" Visibility="Visible">
<Image x:Name="BtnImage" Source="" />
</Viewbox>
</RelativePanel>
<RelativePanel x:Name="BottomRowRelativePanel" Grid.Column="0" Grid.Row="1">
<TextBlock x:Name="BtnTextBlock" Text="Test fdgfxgsg sdg dsgdf sgdf" />
</RelativePanel>
</Grid>
</ControlTemplate>
For example, I want BtnGridTopRow.Height = 2*;
and Button.Width=150;
for a certain type and BtnGridTopRow.Height = 0;
and Button.Width=100;
for another type. The goal is to have the same CommonStates to every button but to have various button style but inheriting of a main style for BorderBrush , background etc...
I looking for the best way to do that because i'm quite new in XAML and UWP but i have 15 years experience in web (PHP,JS,CSS,etc.).
Hopes it's clear enough,
Thanks in advance,