Skip to content

Commit

Permalink
Now working well with Avalonia 11.2.3 + demo switched to .net9
Browse files Browse the repository at this point in the history
  • Loading branch information
flarive committed Jan 10, 2025
1 parent 1f9c42e commit 522becf
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 67 deletions.
37 changes: 12 additions & 25 deletions Avalonia.Themes.Neumorphism/Accents/SystemAccentColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Avalonia.Themes.Neumorphism.Accents
{
internal class SystemAccentColors : IResourceProvider
internal class SystemAccentColors : ResourceProvider
{
public const string AccentKey = "SystemAccentColor";
public const string AccentDark1Key = "SystemAccentColorDark1";
Expand Down Expand Up @@ -74,8 +74,9 @@ internal class SystemAccentColors : IResourceProvider
private Color _systemAccentColorDark1, _systemAccentColorDark2, _systemAccentColorDark3;
private Color _systemAccentColorLight1, _systemAccentColorLight2, _systemAccentColorLight3;

public bool HasResources => true;
public bool TryGetResource(object key, ThemeVariant theme, out object value)
public override bool HasResources => true;

public override bool TryGetResource(object key, ThemeVariant theme, out object value)
{
if (key is string strKey)
{
Expand Down Expand Up @@ -133,38 +134,24 @@ public bool TryGetResource(object key, ThemeVariant theme, out object value)
return false;
}

public IResourceHost Owner { get; private set; }
public event EventHandler OwnerChanged;
public void AddOwner(IResourceHost owner)
{
if (Owner != owner)
if (GetFromOwner(owner) is { } platformSettings)
{
Owner = owner;
OwnerChanged?.Invoke(this, EventArgs.Empty);

if (GetFromOwner(owner) is { } platformSettings)
{
platformSettings.ColorValuesChanged += PlatformSettingsOnColorValuesChanged;
}

_invalidateColors = true;
platformSettings.ColorValuesChanged += PlatformSettingsOnColorValuesChanged;
}

_invalidateColors = true;
}

public void RemoveOwner(IResourceHost owner)
{
if (Owner == owner)
if (GetFromOwner(owner) is { } platformSettings)
{
Owner = null;
OwnerChanged?.Invoke(this, EventArgs.Empty);

if (GetFromOwner(owner) is { } platformSettings)
{
platformSettings.ColorValuesChanged -= PlatformSettingsOnColorValuesChanged;
}

_invalidateColors = true;
platformSettings.ColorValuesChanged -= PlatformSettingsOnColorValuesChanged;
}

_invalidateColors = true;
}

private void EnsureColors()
Expand Down
5 changes: 4 additions & 1 deletion Avalonia.Themes.Neumorphism/Assists/ExpanderAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Avalonia.Themes.Neumorphism.Assist
{
public static class ExpanderAssist
{
public static readonly SolidColorBrush DefaultExpanderStrokeBrushProperty = new SolidColorBrush();


/// <summary>
/// ExpanderWidth
/// </summary>
Expand Down Expand Up @@ -43,7 +46,7 @@ public static double GetExpanderHeight(AvaloniaObject element)
/// ExpanderStrokeBrush
/// </summary>
public static AvaloniaProperty<IBrush> ExpanderStrokeBrushProperty = AvaloniaProperty.RegisterAttached<Expander, IBrush>(
"ExpanderStrokeBrush", typeof(ExpanderAssist));
"ExpanderStrokeBrush", typeof(ExpanderAssist), DefaultExpanderStrokeBrushProperty, true);

public static void SetExpanderStrokeBrush(AvaloniaObject element, IBrush value)
{
Expand Down
14 changes: 7 additions & 7 deletions Avalonia.Themes.Neumorphism/Avalonia.Themes.Neumorphism.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.9" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.9" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.9" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.9" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.9" />
<PackageReference Include="DialogHost.Avalonia" Version="0.7.7" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.5" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.3" />
<PackageReference Include="DialogHost.Avalonia" Version="0.9.1" />
<PackageReference Include="SkiaSharp" Version="3.116.1" />
<AvaloniaResource Include="**/*.xaml" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Avalonia.Themes.Neumorphism/ColorPaletteResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Avalonia.Themes.Neumorphism
/// <remarks>
/// This class can only be used in <see cref="FluentTheme.Palettes"/>.
/// </remarks>
public partial class ColorPaletteResources : AvaloniaObject, IResourceNode
public partial class ColorPaletteResources : ResourceProvider
{
private readonly Dictionary<string, Color> _colors = new(StringComparer.InvariantCulture);

public bool HasResources => _hasAccentColor || _colors.Count > 0;
public override bool HasResources => _hasAccentColor || _colors.Count > 0;

public bool TryGetResource(object key, ThemeVariant theme, out object value)
public override bool TryGetResource(object key, ThemeVariant theme, out object value)
{
if (key is string strKey)
{
Expand Down
1 change: 0 additions & 1 deletion Avalonia.Themes.Neumorphism/Controls/CircularProgress.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Media;

namespace Avalonia.Themes.Neumorphism.Controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public sealed class TemplateResources : ResourceDictionary
{
private void DialogButtonTemplate_OnSelectTemplateKey(object sender, SelectTemplateEventArgs e)
{
if (e.DataContext == null)
{
return;
}

e.TemplateKey = e.DataContext switch
{
ResultBasedDialogButtonViewModel _ => "ObsoleteButton",
Expand All @@ -19,6 +24,11 @@ private void DialogButtonTemplate_OnSelectTemplateKey(object sender, SelectTempl

private void DialogHeaderIconTemplate_OnSelectTemplateKey(object sender, SelectTemplateEventArgs e)
{
if (e.DataContext == null)
{
return;
}

e.TemplateKey = e.DataContext switch
{
DialogIconViewModel _ => "DialogIcon",
Expand Down
9 changes: 7 additions & 2 deletions Avalonia.Themes.Neumorphism/Themes/CalendarDatePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@
</Style>

<!--Floating watermark anim-->
<Style Selector="^:not(^[Text=]):focus-within /template/ TextBlock#floatingWatermark,
^:not(^[Text=]) /template/ TextBlock#floatingWatermark">
<Style Selector="^:not(^[Text=]):focus-within /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="1,-16,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
<Setter Property="MaxWidth" Value="{TemplateBinding Width}" />
</Style>

<Style Selector="^:not(^[Text=]) /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="1,-16,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
<Setter Property="MaxWidth" Value="{TemplateBinding Width}" />
Expand Down
1 change: 0 additions & 1 deletion Avalonia.Themes.Neumorphism/Themes/CircularProgress.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

<!--Default CircularProgress theme-->
<ControlTheme x:Key="{x:Type controls:CircularProgress}" TargetType="controls:CircularProgress">
<Setter Property="StrokeThickness" Value="{TemplateBinding StrokeThickness}"/>
<Setter Property="Template">
<ControlTemplate>
<Grid Background="{TemplateBinding Background}">
Expand Down
2 changes: 0 additions & 2 deletions Avalonia.Themes.Neumorphism/Themes/Expander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1361,8 +1361,6 @@
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="assist:ExpanderAssist.ExpanderStrokeBrush" Value="{TemplateBinding assist:ExpanderAssist.ExpanderStrokeBrush}" />

<Style Selector="^:checked /template/ Path#ExpandCollapseChevron">
<Style.Animations>
<Animation FillMode="Both" Duration="0:0:0.0625">
Expand Down
1 change: 0 additions & 1 deletion Avalonia.Themes.Neumorphism/Themes/ListBoxItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@
<Style Selector="^">
<Setter Property="BorderThickness" Value="1,1,1,0"/>
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}"/>
</Style>

<!--Only first one-->
Expand Down
26 changes: 24 additions & 2 deletions Avalonia.Themes.Neumorphism/Themes/TimePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@
</Style>

<!--Floating watermark anim-->
<Style Selector="^:not(:hasnotime):focus-within /template/ TextBlock#floatingWatermark,
^:not(:hasnotime) /template/ TextBlock#floatingWatermark">
<Style Selector="^:not(:hasnotime):focus-within /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="1,-16,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
<Setter Property="MaxWidth" Value="{TemplateBinding Width}" />
</Style>

<Style Selector="^:not(:hasnotime) /template/ TextBlock#floatingWatermark">
<Setter Property="Margin" Value="1,-16,1,1" />
<Setter Property="RenderTransform" Value="scale(0.75)" />
<Setter Property="MaxWidth" Value="{TemplateBinding Width}" />
Expand Down Expand Up @@ -331,6 +336,18 @@
<RepeatButton Name="PART_MinuteDownButton" Grid.Row="2" Theme="{StaticResource DateTimePickerDownButton}" Background="{DynamicResource MaterialDesignPaper}"/>
</Grid>

<Grid Name="PART_SecondHost" Grid.Column="3" RowDefinitions="Auto,*,Auto" IsVisible="True">
<RepeatButton Name="PART_SecondUpButton" Theme="{StaticResource DateTimePickerDownButton}" Background="{DynamicResource MaterialDesignPaper}"/>
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Hidden">
<DateTimePickerPanel Name="PART_SecondSelector"
PanelType="Second"
ShouldLoop="True" Width="120"
ItemHeight="{DynamicResource TimePickerFlyoutPresenterItemHeight}"/>
</ScrollViewer>
<RepeatButton Name="PART_SecondDownButton" Theme="{StaticResource DateTimePickerDownButton}" Background="{DynamicResource MaterialDesignPaper}"/>
</Grid>

<Grid Name="PART_PeriodHost" Grid.Column="4" RowDefinitions="Auto,*,Auto">
<RepeatButton Name="PART_PeriodUpButton" Grid.Row="0" IsVisible="False" Theme="{StaticResource DateTimePickerUpButton}" Background="{DynamicResource MaterialDesignPaper}"/>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled"
Expand Down Expand Up @@ -359,6 +376,11 @@
HorizontalAlignment="Center"
Width="{DynamicResource TimePickerSpacerThemeWidth}"
Grid.Column="3" />
<Rectangle Name="PART_ThirdSpacer" IsVisible="false"
Fill="{DynamicResource TimePickerFlyoutPresenterSpacerFill}"
HorizontalAlignment="Center"
Width="{DynamicResource TimePickerSpacerThemeWidth}"
Grid.Column="5" />
</Grid>

<Grid Name="AcceptDismissGrid"
Expand Down
22 changes: 10 additions & 12 deletions Neumorphism.Avalonia.Demo/Neumorphism.Avalonia.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- if you want to check exceptions, change this to "Exe" and start your app from the console -->
<OutputType Condition="'$(Configuration.toUpper())' != 'DEBUG'">WinExe</OutputType>
<OutputType Condition="'$(Configuration.toUpper())' == 'DEBUG'">WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ApplicationIcon>Assets/app.ico</ApplicationIcon>
<InvariantGlobalization>false</InvariantGlobalization>
<Nullable>disable</Nullable>
Expand Down Expand Up @@ -48,8 +48,6 @@
<ItemGroup>
<AvaloniaResource Include="Assets/**" />
<AvaloniaResource Include="Images/**" />
<AdditionalFiles Remove="Pages\SnackbarsDemo.axaml" />
<AvaloniaXaml Remove="Pages\TogglesDemo - Copier.axaml" />
<AvaloniaResource Include="NeumorphismXamlDisplay.axaml" />
<None Update="Assets/app.icns" CopyToPublishDirectory="PreserveNewest" Condition="$(RuntimeIdentifier.StartsWith('osx'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -58,18 +56,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.9" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.9" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.9" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.9" />
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.3" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.9" />
<PackageReference Include="DialogHost.Avalonia" Version="0.7.7" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" />
<PackageReference Include="DialogHost.Avalonia" Version="0.9.1" />
<!--Condition below is needed to generate macOS App only.-->
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.0" />
<PackageReference Include="ShowMeTheXaml.Avalonia" Version="1.4.1" />
<PackageReference Include="ShowMeTheXaml.Avalonia.Generator" Version="1.4.1" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
<PackageReference Include="ShowMeTheXaml.Avalonia" Version="1.5.1" />
<PackageReference Include="ShowMeTheXaml.Avalonia.Generator" Version="1.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Neumorphism.Avalonia.Demo/Pages/DialogsDemo.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public partial class DialogsDemo : UserControl
public DialogsDemo()
{
InitializeComponent();

// to avoid binding errors when app start
DataContext = new DialogsDemoViewModel();
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Neumorphism.Avalonia.Demo/Pages/ExpandersDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
assist:ExpanderAssist.ExpanderHeight="42">
<Expander.Header>
<Border Margin="15,0,0,0" VerticalAlignment="Stretch">
<TextBlock VerticalAlignment="Center" Text="Expand me"/>
<TextBlock VerticalAlignment="Center" Text="Expand me2"/>
</Border>
</Expander.Header>
<ScrollViewer Height="104" Padding="0,0,10,0">
Expand Down
2 changes: 1 addition & 1 deletion Neumorphism.Avalonia.Demo/Pages/FieldsDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
</showMeTheXaml:XamlDisplay>
<!--****************************************************************-->
<showMeTheXaml:XamlDisplay UniqueId="NumericUpDown1">
<NumericUpDown Classes="Filled" ButtonSpinnerLocation="Left" Watermark="Select" Minimum="-1000" Maximum="1000" Increment="10" Width="120" Height="42"
<NumericUpDown ButtonSpinnerLocation="Left" Watermark="Select" Minimum="-1000" Maximum="1000" Increment="10" Width="120" Height="42"
ToolTip.Tip="Regular NumericUpDown with default theme applied with button spinner right and allowed values between -1000 and 1000 with an increment of 10"/>
</showMeTheXaml:XamlDisplay>
<!--****************************************************************-->
Expand Down
4 changes: 2 additions & 2 deletions Neumorphism.Avalonia.Demo/Pages/ProgressBarsDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<Setter Property="assist:ProgressBarAssist.CircularInnerContent">
<Setter.Value>
<Template>
<TextBlock Name="PART_InnerContentTextBlock" Width="100" Text="{Binding $parent[ProgressBar].Value, StringFormat={}{0}%}"
<!--<TextBlock Name="PART_InnerContentTextBlock" Width="100" Text="{Binding $parent[ProgressBar].Value, StringFormat={}{0}%}"
Foreground="{TemplateBinding Foreground}" TextAlignment="Center" FontSize="40">
<TextBlock.Styles>
<Style Selector="TextBlock">
Expand All @@ -232,7 +232,7 @@
</Style.Animations>
</Style>
</TextBlock.Styles>
</TextBlock>
</TextBlock>-->
</Template>
</Setter.Value>
</Setter>
Expand Down
3 changes: 1 addition & 2 deletions Neumorphism.Avalonia.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public static class Program
// yet and stuff might break.
public static void Main(string[] args)
{
//dotnet publish -c release --framework net7.0 -r win-x64
//dotnet publish -c release --framework net8.0 -r win-x64
//dotnet publish -c release --framework net9.0 -r win-x64

// how to debug a native aot crash :
// https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/debugging.md
Expand Down
8 changes: 5 additions & 3 deletions Neumorphism.Avalonia.Demo/ViewModels/DialogsDemoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public string OpenDialogWithModelResult
}





public DialogsDemoViewModel()
{
OpenDialogWithViewResult = string.Empty;
OpenDialogWithModelResult = string.Empty;
}

public DialogsDemoViewModel(Window window)
{
Expand Down
2 changes: 1 addition & 1 deletion Neumorphism.Avalonia.Demo/ViewModels/IconsDemoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public IconsDemoViewModel()
.OrderBy(x => x.Kind)
.ToList());


SelectedGroup = _materialIconKinds?.Value?.First();

SearchCommand = new RelayCommand(DoSearchAsync);
}
Expand Down

0 comments on commit 522becf

Please sign in to comment.