Replies: 3 comments 4 replies
-
What's the reason for using
Isn't this already possible with this proposal, just with extra work as I said above? Or am I misunderstanding what you mean here?
I'm conflicted here. I personally like
This ones also tricky, overall the loss of |
Beta Was this translation helpful? Give feedback.
-
Added yet another question, CC @amwx
|
Beta Was this translation helpful? Give feedback.
-
Personally, I don't really feel the need to create specific classes for managing themes. In the app test I used the Style Selector like this: namespace AA2
{
public class Theme
{
public readonly static AttachedProperty<string> NameProperty =
AvaloniaProperty.RegisterAttached<Theme, AvaloniaObject, string>("Name", inherits: true);
public static string GetName(AvaloniaObject avaloniaObject) =>
avaloniaObject.GetValue(NameProperty);
public static void SetName(AvaloniaObject avaloniaObject, string value) =>
avaloniaObject.SetValue(NameProperty, value);
}
} namespace AA2.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private string selectedTheme = "Green";
public string Greeting => "Welcome to Avalonia!";
public string[] Themes => new[] { "Green", "Red" };
public string SelectedTheme { get => selectedTheme; set => this.RaiseAndSetIfChanged(ref selectedTheme, value); }
}
} <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AA2.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:l="using:AA2"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AA2.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="AA2"
l:Theme.Name="{Binding SelectedTheme}"
>
<Window.Styles>
<Style Selector="Window[(l|Theme.Name)=Green]">
<Setter Property="Background" Value="Green"/>
</Style>
<Style Selector="Window[(l|Theme.Name)=Red]">
<Setter Property="Background" Value="Red"/>
</Style>
<Style Selector="Rectangle[(l|Theme.Name)=Green]">
<Setter Property="Fill" Value="Red"/>
</Style>
<Style Selector="Rectangle[(l|Theme.Name)=Red]">
<Setter Property="Fill" Value="Green"/>
</Style>
</Window.Styles>
<StackPanel>
<TextBlock Text="{Binding Greeting}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<ComboBox Items="{Binding Themes}"
SelectedItem="{Binding SelectedTheme}"/>
<Rectangle Stroke="Black" Width="50" Height="50"/>
</StackPanel>
</Window> The only thing I miss compared to WPF and BasedOn. |
Beta Was this translation helpful? Give feedback.
-
UPD: done with #8166
Description
This proposal is about introducing a new API to handle application/system color schemes and defining resources specific to them. It's firstly focused on developers of custom themes.
Theme resources documentation from UWP, to be in context:
https://docs.microsoft.com/en-us/windows/apps/design/style/xaml-theme-resources
Goals:
Would be nice:
Planned APIs:
This API is currently available in themeresource branch (only Default theme is updated to use new markup extension).
Example of usage
Define resources:
Here border background will be updated only when Application.RequestedTheme is changed, but not when ResourceDictionary content is modified (here is the difference from DynamicResource extension).
Questions
Beta Was this translation helpful? Give feedback.
All reactions