The two Layers which used by listViewLayers ListView cannot be added by another Canvas anymore. As far as I'm concerned, the ListView should just contain string items which control Canvas behavior instead of Canvas in ListView.
WinUI 3 ListView Linked To Observablecollection contains layer classes derived from class canvas
mustapha chaibi
65
Reputation points
I want to create an application like photoshop main canvas which groups layer canvases,
a listview which displays the name of the layers and a visibility button via a datatemplate of each layer added to the main canvas.
I created the class layer derived from the class convas
public class Layer : Canvas
{
public string Name { get; set; }
public bool IsVisible { get; set; }
public Layer(Canvas mainCanvas)
{
// Initialize layer properties
Name = "New Layer";
IsVisible = true;
mainCanvas.Children.Add(this);
}
}
ListView Layers
<StackPanel
Grid.Row="1"
Orientation="Vertical">
<ListView
x:Name="listViewLayers"
x:FieldEdit="public"
Background="SeaGreen">
<ListView.ItemTemplate>
<DataTemplate x:DataType="Layer">
<StackPanel>
<TextBlock Text="{x:Bind Name, Mode=TowWay}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
ObservableCollection ocLayers :
ObservableCollection<Layer> ocLayers = new ObservableCollection<Layer>();
ocLayers.Add(new Layer(mainCanvas){Name="AAA"});
ocLayers.Add(new Layer(mainCanvas){Name="BBB"});
listViewLayers.ItemsSource = ocLayers;
DataTemplate with DataType="Canvas" and ObservableCollection<Canvas>
if i add simple canvas Object just for testing it works
DataTemplate with DataType="Layer" and ObservableCollection<Layer>
if i add Layer Object execution hangs
Windows development | Windows App SDK
897 questions
Developer technologies | .NET | Other
Developer technologies | .NET | Other
Microsoft Technologies based on the .NET software framework
4,107 questions
Developer technologies | C#
11,579 questions
Accepted answer
-
Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
2023-02-24T02:52:27.44+00:00