DependencyProperty of Type Delegate
Asked Answered
M

2

6

I have created an attached behavior that is used to execute a Delegate of type Func<bool> when the behavior is invoked. Below is the dependancy property definition.

public static readonly DependencyProperty SendToDetailBehaviorProperty = DependencyProperty.RegisterAttached("SendToDetailBehavior", typeof(Func<bool>), typeof(ListDetailAspectSendToDetailBehavior), new UIPropertyMetadata(null, SendToDetail));

I have it working just as expected however in my XAML I get the following error, preventing the designer from loading.

Property 'SendToDetailBehavior' was not found or is not serializable for type 'SortableListView'

Below you will find the xaml.

<Controls:SortableListView Grid.Row="0"
                                                       Grid.Column="0"
                                                       Name="lvwLocations"
                                                       MinHeight="150"
                                                       MinWidth="{Binding Path=BusinessObject.Locations, ValidatesOnDataErrors=true, Converter={StaticResource AlwaysReturn1Converter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                                       Style="{DynamicResource SortableListViewStyle}"
                                                       ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                       ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                                       IsSynchronizedWithCurrentItem="True"
                                                       **behaviors:ListDetailAspectSendToDetailBehavior.SendToDetailBehavior="{Binding Path=LocationListDetail.SendFocusToDetail}"**
                                                       ItemsSource="{Binding Path=LocationListDetail.MasterList}"
                                                       SelectedItem="{Binding Path=LocationListDetail.DetailItem, Mode=TwoWay}"
                                                       MouseDoubleClick="lvwLocations_MouseDoubleClick">

If I change the underlying type of the Dependancy Property to a bool for example, the error goes away.

As I said the attached behavior is working, only the designer blows up. I have looked for documentation on this and have come up empty. I am hoping someone here has some insight.

Thanks, BDN

Matti answered 8/9, 2010 at 15:17 Comment(0)
P
4

Instead of using delegate, change your dependency property type to Command (I used the DelegateCommand) which will wrap the delegate inside it. I was having the same problem as yours, but it was solved by this method.

Philadelphia answered 22/12, 2010 at 16:59 Comment(0)
P
0

Is this happening in VS 2008, 2010, or Expression Blend? The VS2008 designer is notoriously fragile. As far as fixing it, have you tried using a non-generic delegate type? Something like so:

public delegate bool SendToDetail();

And then your VM would expose a property of that delegate type instead of Func<bool>.

Pylorus answered 8/9, 2010 at 21:47 Comment(1)
I have not tired that. That is a fair suggestion I will give it a try in the morning. It is VS2008 sadly.Matti

© 2022 - 2024 — McMap. All rights reserved.