Skip to content

Commit

Permalink
#87 binding styles in Custom buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Larymar committed Dec 12, 2021
1 parent 05727ea commit 13e4d0f
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 154 deletions.
13 changes: 8 additions & 5 deletions src/MessageBox.Avalonia.Example/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MessageBox.Avalonia.Example.App">
<Application.Styles>
<!--<StyleInclude Source="avares://Avalonia.Themes.Fluent/FluentLight.xaml" />
<Style Selector="Button.default">
<Setter Property="Background" Value="Red" />
</Style>
<!--<StyleInclude Source="avares://Avalonia.Themes.Fluent/FluentLight.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml" />-->
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>

<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
</Application.Styles>
</Application>
</Application>
6 changes: 3 additions & 3 deletions src/MessageBox.Avalonia.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async void MsBoxCustom_Click(object sender, RoutedEventArgs e)
ContentTitle = "title", ContentMessage = "message", FontFamily = "Microsoft YaHei,Simsun",
Icon = MessageBoxAvaloniaEnums.Icon.Error, WindowIcon = null,
ButtonDefinitions = new[]
{ new ButtonDefinition { Name = "确定", Type = MessageBoxAvaloniaEnums.ButtonType.Colored }, },
{ new ButtonDefinition { Name = "确定", IsDefault = true }, },
WindowStartupLocation = WindowStartupLocation.CenterOwner,
});
await messageBoxCustomWindow.ShowDialog(this);
Expand Down Expand Up @@ -115,7 +115,7 @@ public async void MsBoxInput_Click(object sender, RoutedEventArgs e)
{
new ButtonDefinition { Name = "Cancel", IsCancel = true },
new ButtonDefinition
{ Name = "Confirm", Type = MessageBoxAvaloniaEnums.ButtonType.Colored, IsDefault = true }
{ Name = "Confirm", IsDefault = true }
},
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Width = 500,
Expand All @@ -140,7 +140,7 @@ private async void MsBoxCustomImage_Click(object sender, RoutedEventArgs e)
{
new ButtonDefinition { Name = "My", IsCancel = true },
new ButtonDefinition
{ Name = "Buttons", Type = MessageBoxAvaloniaEnums.ButtonType.Colored, IsDefault = true }
{ Name = "Buttons", IsDefault = true }
},
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowIcon = new WindowIcon("./icon-rider.png"),
Expand Down
15 changes: 12 additions & 3 deletions src/MessageBox.Avalonia/MessageBox.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<AvaloniaResource Include="Assets\*" />
<AvaloniaResource Include="Assets\*"/>
<AvaloniaResource Update="Views\MsBoxInputWindow.xaml">
<SubType>Designer</SubType>
<SubType>Designer</SubType>
</AvaloniaResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.8" />
<PackageReference Include="Avalonia" Version="0.10.8"/>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Styles\Dark\Dark.xaml"/>
<UpToDateCheckInput Remove="Styles\MacOs\MacOs.xaml"/>
<UpToDateCheckInput Remove="Styles\Mint\Mint.xaml"/>
<UpToDateCheckInput Remove="Styles\RoundButtons\RoundButtons.xaml"/>
<UpToDateCheckInput Remove="Styles\Ubuntu\Ubuntu.xaml"/>
<UpToDateCheckInput Remove="Styles\Windows\Windows.xaml"/>
<UpToDateCheckInput Remove="Styles\HyperlinkStyle.axaml"/>
</ItemGroup>

</Project>
15 changes: 0 additions & 15 deletions src/MessageBox.Avalonia/Models/ButtonDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
using MessageBox.Avalonia.Enums;

namespace MessageBox.Avalonia.Models
{
public class ButtonDefinition
{
/// <summary>
/// Button type
/// </summary>
private ButtonType _type = ButtonType.Default;

/// <summary>
/// Text in button
/// </summary>
public string Name { get; set; } = "OK";


public ButtonType Type
{
set { _type = value; }
}

public string TypeName => _type.ToString();

/// <summary>
/// When true and if ENTER key is pressed, the button will be called
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions src/MessageBox.Avalonia/Styles/Dark/Dark.xaml

This file was deleted.

13 changes: 0 additions & 13 deletions src/MessageBox.Avalonia/Styles/HyperlinkStyle.axaml

This file was deleted.

28 changes: 0 additions & 28 deletions src/MessageBox.Avalonia/Styles/MacOs/MacOs.xaml

This file was deleted.

21 changes: 0 additions & 21 deletions src/MessageBox.Avalonia/Styles/Mint/Mint.xaml

This file was deleted.

6 changes: 0 additions & 6 deletions src/MessageBox.Avalonia/Styles/RoundButtons/RoundButtons.xaml

This file was deleted.

22 changes: 0 additions & 22 deletions src/MessageBox.Avalonia/Styles/Ubuntu/Ubuntu.xaml

This file was deleted.

18 changes: 0 additions & 18 deletions src/MessageBox.Avalonia/Styles/Windows/Windows.xaml

This file was deleted.

2 changes: 1 addition & 1 deletion src/MessageBox.Avalonia/ViewModels/MsBoxInputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MsBoxInputViewModel(MessageBoxInputParams @params, MsBoxInputWindow msBox
{
ButtonDefinitions = new[]
{
new ButtonDefinition { Name = "Confirm", IsDefault = true, Type = ButtonType.Colored },
new ButtonDefinition { Name = "Confirm", IsDefault = true },
new ButtonDefinition { Name = "Cancel", IsCancel = true }
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/MessageBox.Avalonia/Views/MsBoxCustomWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
<ItemsPresenter.ItemTemplate>
<DataTemplate>
<Button Name="Btn"
Classes="button"
Classes.buttons = "true"
Classes.default = "{Binding IsDefault}"
Classes.cancel = "{Binding IsCancel}"
Tag="{Binding TypeName}"
Command="{Binding DataContext.ButtonClick, RelativeSource={RelativeSource AncestorType=Window, AncestorLevel=1}}"
CommandParameter="{Binding #Btn.Content}"
Expand Down

0 comments on commit 13e4d0f

Please sign in to comment.