Why is this XAML getting the error: Items collection must be empty before using ItemsSource

后端 未结 3 1299
鱼传尺愫
鱼传尺愫 2021-01-04 07:13

Can anyone conjure from this code why the ItemsSource line would be getting a

Items collection must be empty before using

相关标签:
3条回答
  • 2021-01-04 07:33

    You are trying to set the ItemsSource of the ItemsControl but you already have children. Which of those two should apply? The Button you put inside the ItemsControl or the collection you are handing into it as ItemsSource? The error message is perfectly reasonable.

    You would have to either remove the button from the ItemsControl or remove the ItemsSource attribute. You can't insert items and set ItemsSource at the same time.

    0 讨论(0)
  • 2021-01-04 07:40

    Have you looked at this question? It seems like the answer to your problem.

    "Items collection must be empty before using ItemsSource."

    0 讨论(0)
  • 2021-01-04 07:44

    Your ItemsControl has a Button in it. Since there's already an item in the ItemsControl, it's not letting you set its ItemsSource property.

    Move the Button declaration down under the </ItemsControl> closing tag.

    0 讨论(0)
提交回复
热议问题