DependencyProperty of Type Delegate
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, Validates开发者_C百科OnDataErrors=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
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.
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>
.
精彩评论