Open
Description
openedon Feb 11, 2023
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
- Added a tree control to the page to use data binding operations
- Add CS code to use ViewModel
- Added some data in the viewmodel
- Then run the program, and the content in the children is not displayed
Expected behavior
No response
Screenshots
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") },
}
},}; }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment