Skip to content

Problem with ItemsPresenter in code. #5870

Answered by maxkatz6
bonfini7 asked this question in Q&A
Discussion options

You must be logged in to vote

@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:

mainDockpanel.Children.Add(
    new ScrollViewer()
    {          
        Content = new ItemsPresenter()
        {
            [~ItemsPresenter.ItemsProperty] = new TemplateBinding(ListBox.ItemsProperty),
            [~ItemsPresenter.ItemTemplateProperty] = new TemplateBinding(ListBox.ItemTemplateProperty),
            [~ItemsPresenter.ItemsPanelProperty] = new

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@bonfini7
Comment options

Comment options

You must be logged in to vote
1 reply
@bonfini7
Comment options

Answer selected by bonfini7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants