Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Content of the Item in the TreeView is displayed, but the Children content is not displayed! #8171

Open
Linjie123 opened this issue Feb 11, 2023 · 0 comments
Labels
area-TreeView bug Something isn't working team-Controls Issue for the Controls team

Comments

@Linjie123
Copy link

Describe the bug

I wrote following the example of data binding for the TreeView control in a WinUI 3 application, and if I add a layout to Children, then the content of the treeviewitem is not displayed

The following is the page code

   <TreeView  x:Name="Tv_Channel" 
              Grid.Row="1"
              Margin="10"` 
              AllowDrop="True" 
              CanDragItems="True" 
              ItemInvoked="Tv_Channel_ItemInvoked" 
              ItemsSource="{Binding ChannelSource}">

             <TreeView.ItemTemplate>
               <DataTemplate x:DataType="channels:Channel">
                 <TreeViewItem Content="{Binding Layer}" ItemsSource="{Binding Children}">

                            <!--<TreeViewItem.Template>
                            <ControlTemplate>
                                <StackPanel HorizontalAlignment="Left"
                                            VerticalAlignment="Center"
                                            BorderBrush="Transparent"
                                            BorderThickness="1"
                                            Orientation="Vertical">
                                    <TextBlock FontSize="15"
                                               Foreground="White"
                                               Text="{Binding cName}" />
                                    <TextBlock FontSize="8"
                                               Text="{Binding cLink}"
                                               Visibility="Collapsed" />
                                </StackPanel>
                            </ControlTemplate>
                            </TreeViewItem.Template>-->

                  </TreeViewItem>
                </DataTemplate>
             </TreeView.ItemTemplate>       
    </TreeView>

Steps to reproduce the bug

  1. Added a tree control to the page to use data binding operations
  2. Add CS code to use ViewModel
  3. Added some data in the viewmodel
  4. Then run the program, and the content in the children is not displayed

Expected behavior

No response

Screenshots

image

NuGet package version

WinUI 3 - Windows App SDK 1.2.3: 1.2.230118.102

Windows version

Windows 11 (22H2): Build 22621

Additional context

public class VideoViewModel : ObservableObject
{
public ObservableCollection ChannelSource { get; set; }

    public VideoViewModel()
    {
        ChannelSource = new ObservableCollection<Channel>
        {
            new Channel
            {
                Layer = "央视节目",
                Children = new ObservableCollection<Channel>
                {
                    new Channel { cName = "CCTV-1综合", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225642/index.m3u8") },
                    new Channel { cName = "CCTV-2财经", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225643/index.m3u8") },
                    new Channel { cName = "CCTV-3综艺", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225634/index.m3u8") },
                    new Channel { cName = "CCTV-4国际", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225621/index.m3u8") },
                    new Channel { cName = "CCTV-5体育", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225633/index.m3u8") },
                    new Channel { cName = "CCTV-5+体育", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225706/index.m3u8") },
                    new Channel { cName = "CCTV-6电影", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225632/index.m3u8") },
                    new Channel { cName = "CCTV-7军事", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225644/index.m3u8") },
                    new Channel { cName = "CCTV-8电视剧", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225631/index.m3u8") },
                    new Channel { cName = "CCTV-9英语新闻", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225646/index.m3u8") },
                    new Channel { cName = "CCTV-10科教", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225636/index.m3u8") },
                    new Channel { cName = "CCTV-11戏曲", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225628/index.m3u8") },
                    new Channel { cName = "CCTV-12社会与法", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225637/index.m3u8") },
                    new Channel { cName = "CCTV-13新闻", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225638/index.m3u8") },
                    new Channel { cName = "CCTV-14少儿", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225640/index.m3u8") },
                    new Channel { cName = "CCTV-15音乐", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225641/index.m3u8") },
                    new Channel { cName = "CCTV-17农业", cLink = new Uri("http://39.134.115.163:8080/PLTV/88888910/224/3221225908/index.m3u8") },
                }
            },}; }}}
@Linjie123 Linjie123 added the bug Something isn't working label Feb 11, 2023
@gabbybilka gabbybilka added the needs-triage Issue needs to be triaged by the area owners label Mar 13, 2023
@bpulliam bpulliam added area-TreeView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TreeView bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants