Add TextButton

This commit is contained in:
Yoshi Askharoun
2024-05-12 01:40:12 -05:00
parent 81cf60b323
commit 5db9421bfd
4 changed files with 83 additions and 4 deletions
+3 -3
View File
@@ -62,9 +62,9 @@
Foreground="#3B3F42" FontSize="28" FontFamily="segoe zlc" Margin="0,-6,0,0" />
<StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Bottom">
<TextBlock Text="Mods" FontFamily="segoe zuc" FontWeight="ExtraBlack" FontSize="12"/>
<TextBlock Text="Settings" FontFamily="segoe zuc" FontSize="12" Margin="12,0,0,0"/>
<TextBlock Text="About" FontFamily="segoe zuc" FontSize="12" Margin="12,0,0,0"/>
<zmhc:TextButton Text="Mods" FontFamily="segoe zuc" FontSize="12" AllowUncheck="False"/>
<zmhc:TextButton Text="Settings" FontFamily="segoe zuc" FontSize="12" Margin="6,0,0,0"/>
<zmhc:TextButton Text="About" FontFamily="segoe zuc" FontSize="12" Margin="6,0,0,0"/>
</StackPanel>
</Grid>
</Border>
@@ -0,0 +1,37 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:zmhc="clr-namespace:ZuneModdingHelper.Controls">
<Style x:Key="DefaultTextButtonStyle" TargetType="zmhc:TextButton">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="zmhc:TextButton">
<Border Background="Transparent" Padding="{TemplateBinding Padding}" Margin="{TemplateBinding Margin}"
BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<TextBlock x:Name="Label" Text="{TemplateBinding Text}"
Foreground="{TemplateBinding Foreground}" FontWeight="Light"
FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}"/>
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Label" Property="FontWeight" Value="ExtraBlack"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Label" Property="Foreground" Value="#CCC"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="zmhc:TextButton" BasedOn="{StaticResource DefaultTextButtonStyle}"/>
</ResourceDictionary>
@@ -0,0 +1,42 @@
using System.Windows;
using System.Windows.Controls.Primitives;
namespace ZuneModdingHelper.Controls;
public class TextButton : ToggleButton
{
static TextButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextButton), new FrameworkPropertyMetadata(typeof(TextButton)));
}
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
nameof(Text), typeof(string), typeof(TextButton), new PropertyMetadata(string.Empty));
public bool AllowUncheck
{
get => (bool)GetValue(AllowUncheckProperty);
set => SetValue(AllowUncheckProperty, value);
}
public static readonly DependencyProperty AllowUncheckProperty = DependencyProperty.Register(
nameof(AllowUncheck), typeof(bool), typeof(TextButton), new PropertyMetadata(true));
protected override void OnChecked(RoutedEventArgs e)
{
if (!AllowUncheck)
IsEnabled = false;
base.OnChecked(e);
}
protected override void OnUnchecked(RoutedEventArgs e)
{
IsEnabled = true;
base.OnUnchecked(e);
}
}
+1 -1
View File
@@ -5,6 +5,6 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Controls/PathButton.xaml"/>
<ResourceDictionary Source="../Controls/TextButton.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>