WPF Repeater (like) control for collection source?

前端 未结 1 519
北恋
北恋 2020-12-08 10:18

I have a WPF DataGrid bound to ObservableCollection. Each item in my collection has Property which is a List. In m

相关标签:
1条回答
  • 2020-12-08 10:42

    What you did by specifying <DataTemplate .../> inside of ItemsControl is you added this instance of DataTemplate to default property of ItemsControl which is Items. So the exception you got is the expected result: first you specify the ItemsSource, then you modify Items. Instead you should modify ItemTemplate property on your ItemsControl like so:

    <ItemsControl ItemsSource="{Binding Path=Exchanges}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Label>test</Label>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
    
    0 讨论(0)
提交回复
热议问题