在 XAML 中呈现 ItemsSource 的一个测试元素

Render one test element of ItemsSource in XAML

我有一个要设置样式的 XAML 元素,但由于它位于动态列表(我使用 Name="" 设置)中,所以我看不到任何更改在写 XAML.

有没有办法让 Visual Studio 呈现一个(或几个)测试元素,以便我可以看到我在做什么?

如果您设置控件的 DataContext,那么 XAML Designer 将从中获取任何数据。

<UserControl.Resources>
    <local:MyViewModel x:Key="MyViewModel"/>
</UserControl.Resources>

<ListBox DataContext="{StaticResource MyViewModel}" ItemsSource="{Binding Items}">
</ListBox>


public class MyViewModel
{
    public string[] Items { get; set; }
    public MyViewModel()
    {
        Items = new[] { "Item1", "Item2", "Item3" };
    }
}