ItemsPanelTemplate from ListView seems to mistakenly exclude

I created a custom control that contains a ListView with a custom item ItemsPanelTemplate.

<UserControl x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="thisUserControl">
<ListView ItemsSource="{Binding Source={StaticResource cvs}}"
          Name="mainListView">
    <ListView.GroupStyle>
        <GroupStyle>
            ...
        </GroupStyle>
    </ListView.GroupStyle>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <cd:TimeLinePanel UnitsPerSecond="{Binding ElementName=thisUserControl,Path=DataContext.UnitsPerSecond}" Start="{Binding ElementName=thisUserControl, Path=DataContext.Start}"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

The DataContext UserControl has two properties, Start and UnitsPerSecond. Since I use groups, I can't just write

Start={Binding Path=.Start}

So I used the code above. But if I changed the start binding to this, I get an exception:

VisualTree of ItemsPanelTemplate must be a single item.

Obviously, an ItemPanelTemplate has only one item.

So what could be the problem? My user panel does not create any elements. He just suits them.

+3
source share
1 answer

, , , "" TimeLinePanel ( - 1 "VisualChildrenCount" ). , "" , ItemsControl - ItemPanelTemplate. ItemsControl .

ListView : .

<ListView.Template>
    <ControlTemplate>
        <cd:TimeLinePanel IsItemsHost="True" UnitsPerSecond="..."/>
    <ControlTemplate>
</ListView.ItemsPanel>

CodeProject (http://www.codeproject.com/KB/WPF/ConceptualChildren.aspx), , , .

+6

Source: https://habr.com/ru/post/1716246/


All Articles