xaml中Observable集合的嵌套数据绑定

时间:2018-11-22 14:43:40

标签: c# mvvm

我正在创建一个WPF应用程序,它将文件作为输入并为文件中的不同对象绘制图形。

<ScrollViewer Name="scrollViewer" HorizontalScrollBarVisibility="Auto"   Grid.Row="2" Grid.Column="3" 
                    Height= "600" Width="Auto">
            <ItemsControl ItemsSource="{Binding BiggerCollection}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas x:Name="front_canvas" Background="White" Height="1200" Width="{Binding CanvasWidth}"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <ItemsControl ItemsSource="{Binding Lines}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Line X1="{Binding From.X}" Y1="{Binding From.Y}"
                                    X2="{Binding To.X}" Y2="{Binding To.Y}"
                                    Stroke="Black" StrokeThickness="1"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

属性“ Lines”是CustomLineViewModel的集合。在CustomLineViewModel中,有两个名为“从”和“到”的属性。两者都是数据类型Point。我在屏幕上看不到任何东西。后端逻辑很好,因为在调试期间我检查了不同变量的值。

0 个答案:

没有答案