tags:

views:

180

answers:

2

This XAML compiles and runs without any runtime errors:

<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>

But at design time in Blend this is marked as invalid XAML---and in Visual Studio design time the "Load Cancelled" screen shows (but loads properly after clicking Resume loading the designer).

+1  A: 

Blend only supports a subset of WPF. I have noticed that EventSetters kill blend as well. I have the same problem as you. I have many windows which run fine, but cant be viewed in blend for odd reasons.

http://stackoverflow.com/questions/1878674/strategy-to-diagnose-expression-blend-2-failure-to-open-window

I think maybe the Custom:DataGrid might not be supported. I dont know, just guessing. If your window instantiates and runs fine, then i guess blend is bugged.

Andrew Keith
A: 

Allright I fixed the issue like follows:

Change:

xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit

To:

xmlns:Custom="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"

Make sure you have a good version of the WpfToolkit. Make a reference to the Toolkit and you can work with it.

pipelinecache
My project has an explicit reference to `C:\Program Files (x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll` and this is not working for me...
rasx