wekempf

I've created two attached properties, call them WidgetType and WidgetInstance. WidgetType is a normal attached property, and WidgetInstance is a read-only attached property. In the WidgetType property metadata I've specified a property changed callback which allocates an instance of the specified type and assigns it to the WidgetInstance property using the DP key. When I run this application, it appears to function correctly. However, the designer (VisualStudio 2008 Beta 2) fails to display the window, complaining that the read-only attached property requires an authorization key, failing on the line that sets the WidgetType property. I've Googled and search MSDN but can't find any reference to why the designer would be failing on me here. Anyone got any idea what's wrong and how to fix it



Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

Marco Zhou - MSFT

Hi,

Read only attached property doesn't require any type of authorization key. You might experience other issues here. Could you please tell us a bit about what type of application are you building Does your application have any component which requires authorization

Thanks





Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

wekempf

No, my application doesn't have any other component that requires authorization. And the error very clearly indicates what the problem is, I just don't understand why it has an issue.

'WidgetInstance' property was registered as read-only and cannot be modified without an authorization key.

Not much ambiguity there, as to what the designer thinks is the issue. However, the application does compile and run appropriately. Further, if you comment out the call to set the read-only property, the designer no longer has an issue.

Code Block

private static readonly DependencyPropertyKey WidgetInstancePropertyKey =

DependencyProperty.REgisterAtachedReadOnly("WidgetInstance", typeof(IWidget), typeof(WidgetHelper),

new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));

public static readonly DependencyProperty WidgetInstanceProperty = WidgetInstancePropertyKey.DependencyProperty;

private static void SetWidgetInstance(DependencyObject obj, IWidget value)

{

obj.SetValue(WidgetInstancePropertyKey, value); // comment this out and the error goes away

}





Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

Marco Zhou - MSFT

Well, Since what you need is a read-only attached property, I think you'd better not to expose the ability to modify its value to outside consumers through the SetXXX method, even though this will not break anything except irritating the designer

Thanks





Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

wekempf

It's not exposed. The SetWidgetInstance method was declared private. The code here closely follows the documented procedure for creating a read-only attached property. Further, the designer isn't "irritated", an exception is thrown and the designer fails to display the visuals. This means the designer is rendered unusable. This isn't an irritation, but a show stopper.





Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

Ben Carter - MSFT

I checked our source code, and that exception should only be thrown if calling SetValue with the non-key DP. I'm trying to re-create your project under VS 2008 to confirm the exception and see what's going on.

Ben






Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

wekempf

I'm most certainly using the key and not the DP itself. I'd be willing to share the code, though I won't publish it in the public arena just yet. If you want to contact me, go to http://wekempf.spaces.live.com and leave me a message with how to contact via e-mail (sorry for the round about stuff here, but I'm attempting to avoid spam).





Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

Ben Carter - MSFT

I was able to reproduce the problem under VS 2008 Beta 2. I then checked to see if it still occurs on a later build, and it does not. So, the good news is that it appears to be fixed. The bad news is that it appears to have been a bug in the designer, and I don't know of a workaround other than waiting for the next release of VS 2008.

Ben






Re: Windows Presentation Foundation (WPF) Read-only attached property and authorization key

wekempf

Thanks. I can work around this by not making the call when in design mode for now, and fix it when VS 2008 is in my grubby hands. Thankfully, that won't be long now. At least you confirmed I'm not going insane here.