tags:

views:

1531

answers:

3

I'm running into a problem with the new Expression Blend behaviors.

I have a customized Behavior<T> class developed using the Expression Blend 3 SDK.

The behavior works properly, and the solution compiles. That is perfect. I have all of my references (System.Windows.Interactivity.dll + Microsoft.Expression.Interactions.dll) setup in my projects that reference the behavior.

In addition, as I mentioned, Visual Studio compiles the project fine.

However, if I load the XAML file in the Visual Studio designer, I get the following error after the solution compiles:

Error 1 The attachable property 'Behaviors' was not found in type 'Interaction'. C:\Path\To\MyFile.xaml 19 14 MyApplication

That line of the file is the first line of the following:

<Interactivity:Interaction.Behaviors>
    <Behaviors:DoubleTextBoxBehavior />
</Interactivity:Interaction.Behaviors>

My window reference is setup with:

xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

I've even eliminated my custom behavior as a possibility. I can just include the following line, and "break" the designer:

<Interactivity:Interaction.Behaviors />

As far as I can tell, this should work. There shouldn't be an error. The compiler handles this fine, but Visual Studio won't load this in the designer any time I add the behavior line.

Does anybody have an idea of what can cause this, and how to fix it?


Edit:

I've done some more testing, and this appears to be an error occurring only within the Windows Presentation Foundation Designer windows within Visual Studio 2008 (with sp1). The project works fine, and no error is reported, provided I only use the XML editor. If I open this in the Designer, however, it reports the error and shows a Problem Loading designer.

The error does not appear unless the XAML file is opened in the VS designer.

+1  A: 

Hi Reed.

I've tried to reproduce your issue, but I couldn't. I have created the following WPF application:

<Window x:Class="WpfBehaviorsTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="Window1" Height="300" Width="300">
<Grid>
    <Interactivity:Interaction.Behaviors/>
</Grid>
</Window>

Everything works just fine before and after I compile my project. Could you test if this works for you? What version of MS Blend SDK do you use? What version of Visual Studio? Just to be sure: we speak about WPF application, not Silverlight, correct?

Update: You have exactly the same configuration as I do. The only problem is that it works here, but doesn't work on your side. Let's squash this insect by the following checks:

  1. What version of "System.Windows.Interactivity" assembly get's loaded by designer? You could run another instance of MS Visual Studio and attach to the first VS process with "buggy"-designer. Go to Debug->Windows->Modules and check the version of System.Windows.Interactivity.dll. If it looks good you still can go and double check it with Reflector. Does it has Interaction class? Is there BehaviorsProperty in it?

  2. What exactly is happening there inside? If assembly that we've checked in step 1 is correct, let's run heavy artillery. In fact I effectively use this approach quite often, whenever I have VS/Blend designer issues. Just run another instance of Visual Studio. Turn on breaks on all CLR exceptions (Debug -> Exceptions-> Check the box after CLR Exceptions). It might also help to turn on .NET source code debugging. Attach to the instance with invalid designer. Reload designer. Now, instead of seeing confusing message, attached Studio will bring us to the very heart of the Exception. What's there?

Anvaka
This exact code does the problem for me. I'm using VS 2008 sp1, with Expression Blend SDK 3, in a WPF application. It compiles and runs, but when I open this xaml file in the VS Designer, I get the error.
Reed Copsey
The error only occurs once loaded in the Designer window - the project compiles correctly. There is no error if loaded in the XML Editor (only the WPF Designer).
Reed Copsey
Anvaka: I really appreciate all of the work on this. It turns out it's due to a known issue that was addressed in KB958017.
Reed Copsey
Reed, no problem. I'm glad you found solution :). Cheers.
Anvaka
+3  A: 

This is due to known issue in Visual Studio, and is addressed by a hotfix: KB958017.

This can be corrected by downloading and installing the KB958017 Rollup Fixes for Visual Studio Designer.

Reed Copsey