-
Hi, Currently I'm working on a basic file manager sofware with Avalonia and at this point is really got stuck.
Here is the associated DataTemplate:
These xaml solutions are work like a charm. Now i want to do the same stuff but more like in a dynamic approach (so basically the same things just in Method that returns with the custom (dynamic) data template:
Method that returns the custom template with the ItemsPresenter:
And the results i would like to get VS the wrong result: Sorry for the long topic. This is the my first GitHub discussion that i have ever opened. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @bonfini7 - congratulations on your first GitHub discussion ;) Do you think you got put a minimal repro in a github repository so we can take a look? At first glance I don't see anything wrong, but it's hard to tell. |
Beta Was this translation helpful? Give feedback.
-
@bonfini7 you forgot TemplateBindings in both your templates (xaml and code behind). In case of XAML template it might was done implicitly, but it didn't work with code behind. Code that worked for me: mainDockpanel.Children.Add(
new ScrollViewer()
{
Content = new ItemsPresenter()
{
[~ItemsPresenter.ItemsProperty] = new TemplateBinding(ListBox.ItemsProperty),
[~ItemsPresenter.ItemTemplateProperty] = new TemplateBinding(ListBox.ItemTemplateProperty),
[~ItemsPresenter.ItemsPanelProperty] = new TemplateBinding(ListBox.ItemsPanelProperty),
[~ItemsPresenter.MarginProperty] = new TemplateBinding(ListBox.MarginProperty),
[~ItemsPresenter.VirtualizationModeProperty] = new TemplateBinding(ListBox.VirtualizationModeProperty),
}
}); |
Beta Was this translation helpful? Give feedback.
@bonfini7 you forgot TemplateBindings in both your templates (xaml and code behind). In case of XAML template it might was done implicitly, but it didn't work with code behind.
Missed template bindings:
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/ListBox.xaml#L29-L33
Code that worked for me: