feat: introduce new button style
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
<ResourceDictionary Source="/Frontend/Styles/AccessoryIconControl.xaml"/>
|
<ResourceDictionary Source="/Frontend/Styles/AccessoryIconControl.xaml"/>
|
||||||
<ResourceDictionary Source="/Frontend/Styles/GenericButton.xaml"/>
|
<ResourceDictionary Source="/Frontend/Styles/GenericButton.xaml"/>
|
||||||
<ResourceDictionary Source="/Frontend/Styles/TextboxErrorTemplate.xaml"/>
|
<ResourceDictionary Source="/Frontend/Styles/TextboxErrorTemplate.xaml"/>
|
||||||
|
<ResourceDictionary Source="/Frontend/Widgets/IconButton.xaml"/>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
@@ -61,10 +61,10 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right" Margin="10">
|
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right" Margin="10">
|
||||||
<Button Content="OK" Margin="5" Style="{StaticResource OkButtonStyle}" IsDefault="True"
|
<widget:IconButton Margin="5" Style="{StaticResource OkIconButtonStyle}" IsDefault="True"
|
||||||
Command="{Binding OkCommand}"/>
|
Command="{Binding OkCommand}"/>
|
||||||
<Button Content="Cancel" Margin="5" Style="{StaticResource CancelButtonStyle}"
|
<widget:IconButton Margin="5" Style="{StaticResource CancelIconButtonStyle}"
|
||||||
Command="{Binding CancelCommand}"/>
|
Command="{Binding CancelCommand}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace BallanceTasEditor.Frontend.Widgets {
|
||||||
|
public class IconButton : Button {
|
||||||
|
static IconButton() {
|
||||||
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(IconButton), new FrameworkPropertyMetadata(typeof(IconButton)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ButtonText {
|
||||||
|
get { return (string)GetValue(ButtonTextProperty); }
|
||||||
|
set { SetValue(ButtonTextProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a DependencyProperty as the backing store for ButtonText. This enables animation, styling, binding, etc...
|
||||||
|
public static readonly DependencyProperty ButtonTextProperty =
|
||||||
|
DependencyProperty.Register("ButtonText", typeof(string), typeof(IconButton));
|
||||||
|
|
||||||
|
public ImageSource ButtonIcon {
|
||||||
|
get { return (ImageSource)GetValue(ButtonIconProperty); }
|
||||||
|
set { SetValue(ButtonIconProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a DependencyProperty as the backing store for ButtonIcon. This enables animation, styling, binding, etc...
|
||||||
|
public static readonly DependencyProperty ButtonIconProperty =
|
||||||
|
DependencyProperty.Register("ButtonIcon", typeof(ImageSource), typeof(IconButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:widget="clr-namespace:BallanceTasEditor.Frontend.Widgets">
|
||||||
|
|
||||||
|
<Style x:Key="IconButtonStyle" TargetType="{x:Type widget:IconButton}" BasedOn="{StaticResource {x:Type Button}}">
|
||||||
|
<!--
|
||||||
|
YYC MARK:
|
||||||
|
I was forced to use ContentTemplate to implement this.
|
||||||
|
If I directly set Content, it will trigger weird image reuse issue,
|
||||||
|
which cause only one IconButton can be displayed correctly.
|
||||||
|
-->
|
||||||
|
<Setter Property="ContentTemplate">
|
||||||
|
<Setter.Value>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Image Source="{Binding ButtonIcon, RelativeSource={RelativeSource AncestorType=widget:IconButton}, Mode=OneWay}"
|
||||||
|
RenderOptions.BitmapScalingMode="HighQuality"
|
||||||
|
Width="16" Height="16" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock Text="{Binding ButtonText, RelativeSource={RelativeSource AncestorType=widget:IconButton}, Mode=OneWay}"
|
||||||
|
Margin="5,0,0,0" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style TargetType="{x:Type widget:IconButton}" BasedOn="{StaticResource IconButtonStyle}"/>
|
||||||
|
|
||||||
|
<Style x:Key="OkIconButtonStyle" TargetType="{x:Type widget:IconButton}" BasedOn="{StaticResource IconButtonStyle}">
|
||||||
|
<Setter Property="Padding" Value="5"/>
|
||||||
|
<Setter Property="MinWidth" Value="80"/>
|
||||||
|
<Setter Property="ButtonIcon" Value="/Frontend/Assets/Ok.ico"/>
|
||||||
|
<Setter Property="ButtonText" Value="OK"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="CancelIconButtonStyle" TargetType="{x:Type widget:IconButton}" BasedOn="{StaticResource IconButtonStyle}">
|
||||||
|
<Setter Property="Padding" Value="5"/>
|
||||||
|
<Setter Property="MinWidth" Value="80"/>
|
||||||
|
<Setter Property="ButtonIcon" Value="/Frontend/Assets/Cancel.ico"/>
|
||||||
|
<Setter Property="ButtonText" Value="Cancel"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in New Issue
Block a user