DependencyProperty for delegate type

I created an attached behavior that is used to execute a delegate of type Func<bool> when invoking the behavior. The following is a definition of a dependency property.

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

I work as expected, however in my XAML I get the following error, preventing the developer from loading.

The property "SendToDetailBehavior" was not found or is not serializable for type 'SortableListView'

Below you will find 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 changed the base type of the Dependancy property to bool , for example, the error will disappear.

As I said, the attached behavior works, only the designer explodes. I was looking for documentation on this and came up empty. I hope someone has an understanding.

Thanks, BDN

+6
wpf dependency-properties attached-properties attachedbehaviors
source share
2 answers

Instead of using a delegate, change your dependency property type to a command (I used DelegateCommand) that wraps the delegate inside it. I had the same problem as you, but it was solved by this method.

+4
source share

Does this happen in VS 2008, 2010 or Expression Blend? The designer of VS2008 is known as fragile. Regarding fixing it, have you tried using a non-generic delegate type? Something like that:

 public delegate bool SendToDetail(); 

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

0
source share

All Articles