Wpf 为什么这个XAML无效?
此XAML编译和运行时没有任何运行时错误:Wpf 为什么这个XAML无效?,wpf,xaml,blend,Wpf,Xaml,Blend,此XAML编译和运行时没有任何运行时错误: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schema
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit" x:Class="WpfApplication1.Window1"
Title="Window1" Height="300" Width="300" mc:Ignorable="d">
<StackPanel Orientation="Vertical" d:LayoutOverrides="Height" DataContext="{Binding Source={StaticResource booksDataSource}}">
<Custom:DataGrid ItemsSource="{Binding Mode=Default, XPath=/catalog/book}" AutoGenerateColumns="False">
<Custom:DataGrid.Resources>
<ControlTemplate x:Key="TemplateLoverBirds">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Great book!" />
<TextBlock x:Name="textBlock" Text="{Binding Mode=Default, XPath=title}" />
</StackPanel>
</ControlTemplate>
</Custom:DataGrid.Resources>
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding Mode=Default, XPath=author}"/>
<Custom:DataGridTemplateColumn>
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Control x:Name="TitleControl">
<Control.Template>
<ControlTemplate TargetType="{x:Type Control}">
<TextBlock Text="{Binding Mode=Default, XPath=title}" />
</ControlTemplate>
</Control.Template>
</Control>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding XPath=title}" Value="Lover Birds">
<Setter TargetName="TitleControl" Property="Template" Value="{StaticResource TemplateLoverBirds}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</StackPanel>
</Window>
但是在Blend中的设计时,它被标记为无效的XAML——在Visual Studio设计时,会显示“Load Cancelled”(加载已取消)屏幕(但在单击继续加载设计器后会正确加载)。Blend仅支持WPF的一个子集。我注意到,事件策划者也会杀死blend。我和你有同样的问题。我有许多运行良好的窗口,但由于奇怪的原因无法在混合模式下查看
我认为可能不支持自定义:DataGrid。我不知道,只是猜测而已。如果您的窗口实例化并运行良好,那么我猜blend有错误。好吧,我修复了如下问题: 更改:
xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit
致:
确保您有一个好的WpfToolkit版本。引用工具箱,您就可以使用它。我的项目明确引用了
C:\ProgramFiles(x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll
,这不适用于我。。。
xmlns:Custom="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"