UWP TreeView HasUnrealizedChildren при использовании {x: Bind}

Я читал здесь: Microsoft Docs: TreeView, и я нашел свойство HasUnrealizedChildren, которое идеально подходит для моего случая, поскольку у меня есть TreeStructure, который может быть очень глубоким и очень сложным. Я не понял, как его использовать в случае привязки данных. В моем случае так же:

                <muxc:TreeView Name="DessertTree"
                                  SelectionMode="Multiple"
                                  ItemsSource="{x:Bind DataSource}">
                <muxc:TreeView.ItemTemplate>
                    <DataTemplate x:DataType="local:Item">
                        <muxc:TreeViewItem
                            ItemsSource="{x:Bind Children}"
                            Content="{x:Bind Name}"/>
                    </DataTemplate>
                </muxc:TreeView.ItemTemplate>
            </muxc:TreeView>

Но я не хочу загружать все дочерние элементы, я хочу загружать их только в развернутом виде, как объяснено в примере. Но для того, чтобы показать Expand gliph, мне нужно установить HasUnrealizedChildren для корневых элементов.


person Massimo Savazzi    schedule 16.05.2020    source источник


Ответы (1)


Вот уловка:

    <DataTemplate
        x:Key="ItemTemplate"
        x:DataType="model:MTreeViewBase"
        x:DefaultBindMode="OneWay">
        <winui:TreeViewItem  IsExpanded="False" ItemsSource="{x:Bind Visits}" HasUnrealizedChildren="{x:Bind Loaded, Converter={StaticResource NotEnumToBooleanConverter}, ConverterParameter=Loaded, Mode=OneWay}">
            <controls1:TreeViewControl Data="{x:Bind}" />
        </winui:TreeViewItem>
    </DataTemplate>

Я использовал конвертер, чтобы изменить HasUnrealizedChildren на false после загрузки элемента

person Massimo Savazzi    schedule 16.05.2020