简体   繁体   中英

Visual Studio Designer broken using Expression Blend SDK Behavior

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.

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 .

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?

I am using VS2010 and I experienced the same problem but found a solution.

I had a two projects in my solution. Project "A" that used the Behaviors in a silverlight control (defined in the xaml). I then referenced the control in project "A" inside the active silverlight project "B" which was being executed. I kept getting the error The attachable property 'Behaviors' was not found in type 'Interaction'

When I added the System.Windows.Interactivity reference to project "B" it fixed my runtime error.

I am not sure why that reference was not being loaded because it was being utilized by the control from project "A" but it wasn't. Oh well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM