DataTemplate 中的自定义数据类型破坏了 WPF 设计器
为什么 DataTemplate 行会破坏 Visual Studio 2008 中的 WPF 设计器?
程序编译并正常运行。 DataTemplate 按其应有的方式应用。然而,整个 DataTemplate 代码块都带有红色下划线,当我只是“构建”程序而不运行时,我收到错误“类型引用找不到名为“字符”的公共类型”,
为什么它在设计者但程序是否正确应用了模板?
<UserControl x:Class="WPF_Tests.Tests.TwoCollecViews.TwoViews"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DetailsPane="clr-namespace:WPF_Tests.Tests.DetailsPane"
>
<UserControl.Resources>
<DataTemplate DataType="{x:Type DetailsPane:Character}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid>
<ListBox ItemsSource="{Binding Path=Characters}" />
</Grid>
</UserControl>
编辑:我被告知这可能是 Visual Studio 2008 中的一个错误,因为它在 2010 年工作正常。您可以在此处下载代码:http://www.mediafire.com/?z1myytvwm4n - Test/TwoColec xaml 文件的设计器将破坏此代码。
Why does the DataTemplate line break the WPF designer in Visual Studio 2008?
The program compiles and runs properly. The DataTemplate is applied as it should. However the entire DataTemplate block of code is underlined in red, and when I simply "build" the program without running, I get the error "Type reference cannot find public type named 'Character'"
How come it can't find it in the designer yet the program applies the template properly?
<UserControl x:Class="WPF_Tests.Tests.TwoCollecViews.TwoViews"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DetailsPane="clr-namespace:WPF_Tests.Tests.DetailsPane"
>
<UserControl.Resources>
<DataTemplate DataType="{x:Type DetailsPane:Character}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid>
<ListBox ItemsSource="{Binding Path=Characters}" />
</Grid>
</UserControl>
EDIT: I am being told that this may be a bug in Visual Studio 2008, as it worked correctly in 2010. You can download the code here: http://www.mediafire.com/?z1myytvwm4n - The Test/TwoCollec xaml file's designer will break with this code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是 Visual Studio 2008 中的一个错误。您可以通过将程序集名称(右键单击项目“WPF Tests”/属性)从“WPF Tests”更改为“WPF_Tests”来解决此问题。我在你的项目中尝试过它,它似乎可以工作(重新启动 Visual Studio 后)。
(此解决方法的功劳在于:http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21d72064-354c-432e-8227-ba4e21f4089f)
Yes, it's a bug in Visual Studio 2008. You can workaround it by changing your assembly name (right-click on Project "WPF Tests"/Properties) from "WPF Tests" to "WPF_Tests". I tried it with your project and it seems to work (after restarting Visual Studio).
(Credit for this workaround goes to: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21d72064-354c-432e-8227-ba4e21f4089f)