【发布时间】:2011-12-06 22:03:27
【问题描述】:
这可能是一个愚蠢的问题,但是否可以将一些示例数据定义为 DataContext 以便在 DesignView 中查看我的 DataTemplate?
目前我总是需要运行我的应用程序来查看我的更改是否有效。
例如使用以下代码 DesignView 只显示一个空列表框:
<ListBox x:Name="standardLayoutListBox" ItemsSource="{Binding myListboxItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Column="0" Content="{Binding text1}" />
<Label Grid.Column="1" Content="{Binding text2}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
【问题讨论】:
-
请参阅这篇文章中提出的解决方案:stackoverflow.com/questions/1889966/…
-
我已经为此阅读了很多示例,但我真的无法在设计时填充这个简单的列表框。我确定我错过了一些东西,但我不知道是什么。您可以为我的列表框提供一个工作示例吗?
-
示例代码见我的回答。
-
我现在正在运行它,但我不知道为什么:-( 对于那些感兴趣的人,这个示例帮助很大:st-lange.net/post/…
标签: wpf xaml datatemplate designview