Closed jmkinzer closed 1 year ago
Looks like I need to add binding support for styles
That would really helpful - thanks!
@jmkinzer I pushed update with binding support in styles. Usage sample:
public class StylesSampleView : ViewBase
{
protected override object Build() =>
new StackPanel()
.Children(new Control[]
{
new TabControl()
.ItemTemplate<TabVm>(tab => new TextBlock().Text(tab.Title))
.ContentTemplate(new FuncDataTemplate<TabVm>((item, ns) => new TextBlock().Text(item?.Content)))
.Items(Tabs)
.Styles(
new Style<TabItem>()
.IsEnabled(new Binding(nameof(TabVm.Enabled)))
.Foreground(Brushes.YellowGreen)
)
});
public List<TabVm> Tabs { get; set; } = new()
{
new TabVm("Tab1"),
new TabVm("Tab2"),
new TabVm("Disabled tab",false)
};
}
public class TabVm
{
public TabVm(string title, bool enabled = true)
{
Title = title;
Enabled = enabled;
}
public string Title { get; }
public bool Enabled { get; }
public string Content => Title + " Content";
}
Fantastic, exactly what I needed. Thanks!
I am trying to replicate the tabcontrol xaml as follows (omitting the item/content templates as those are not an issue):
But I can't see how to provide bindings for the IsEnabled property. The first issue is that there do not appear to be extension methods to create a binding in a style (and I'm not sure how one would bind in the control template). The second is I'm not actually sure what the binding path would actually look like in any case. It would also be really nice to have an approach that detects binding errors in such cases at compile time (perhaps using compiledbindingextension?)
Could an example be created here? Thank you!