-
The uno documentation Resource Dictionaries: Creating Resources claims, that in order to create Theme Resource Dictionary one should write following code: public static class MyResources
{
public static readonly ThemeResource<Color> MyColor =
ThemeResource.Create<Color>(nameof(MyColor), "#FF0000", "#FFFFFF");
} this code produces a compilation error: The Q1: How should I create my theme resources correctly? I suppose you have a bug in documentaion and you intended to write the following: public static class MyResources
{
public static readonly Resource<Color> MyColor =
ThemeResource.Create<Color>(nameof(MyColor), "#FF0000", "#FFFFFF");
} Q2: How should I bind themes to template control? internal class MyControl: Control
{
public MyControl() => this
.DataContext(new BindableMyControlModel(), (page, vm) => page
.Resources(r => r.Add(MyResources.MyColor))
.Style(new MyStyle())
);
}
class MyStyle
{
public MyStyle() => Setters(s => s.Template(c =>
new Border()
.VerticalAlignment(VerticalAlignment.Top)
.HorizontalAlignment(HorizontalAlignment.Center)
.Width(100)
.Height(100)
.BorderThickness(1)
.BorderBrush(MyResources.MyColor); // this is how documentation suggest to make an implicit binding,
));
} Following does not work:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
ok. I found the error: internal class MyControl: Control
{
public MyControl() => this
.Resources(r => r.Add(MyResources.MyColor)) // resources first
.DataContext(new BindableMyControlModel(), (page, vm) => page // than vm...
.Style(new MyStyle())
);
} ... and use explicit This is a pity, because the coolest syntax that is mentioned in the documentation, that automatically generates implicit binding unfortunately does not compile: Is these two bugs? will they be fixed? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
So
ThemeResource
is a static public class.ThemeResource<T>
which is the one you're trying to use in your sample is an internal sealed class and it's meant to be because it's the BindingProvider that is used internally by theIDependencyPropertyBuilder
if you didx => x.ThemeResource("Foo")
You are correct there is a bug in the docs. I will have a PR up this morning to fix it. Thanks for bringing it to my attention. (see #2269)
This one gets a little trickier. There are some edge cases for Resource resolution that are very hard for us to properly replicate from C# Markup because w…