-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React-like contexts #3130
Comments
How exactly is it different from <ContentControl>
<ContentControl.Resources>
<Color x:Key="ThemePrimaryColor">#123456</Color>
</ContentControl.Resources>
<SomeElement Color="{DynamicResource ThemePrimaryColor}"/>
</ContentControl> Also, you can achieve contexts via inherited attached properties. e. g. class ThemeContext
{
public Color PrimaryColor { get; set; }
public static AvaloniaProperty CurrentProperty = AvaloniaProperty.RegisterAttached(...
... attached getter and setter here ...
} <ContentControl>
<local:ThemeContext.Current>
<local:ThemeContext Color="#123456"/>
</local:ThemeContext.Current>
<SomeElement Color="{Binding (local:ThemeContext.Current).Color, RelativeSource={RelativeSource Self}}"/>
</ContentControl> |
Another way would be a class inheriting from ContentControl, e. g. class ThemeContext : ContentControl
{
public Color PrimaryColor { get; set; }
} <local:ThemeContext PrimaryColor="#123456">
<SomeElement Color="{Binding $parent[local:ThemeContext].PrimaryColor}" />
</ThemeContext> |
Hmm, nice. Sorry for asking without knowing that. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In React Context is an object which contains some value and exports a Provider - an element which provides value to all children, overridding parents' values, and "users" - functions which get value of the nearest provider of given type. On context update users are updated too.
Would be nice in conjunction with control themes as in #2769 .
This might look like below; sorry if i have any mistakes - i am not good enough in xaml, although i hope you get the idea.
The text was updated successfully, but these errors were encountered: