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

4

2 回答 2

4

不使用委托,而是将您的依赖属性类型更改为 Command(我使用了 DelegateCommand),这会将委托包装在其中。我遇到了和你一样的问题,但是用这个方法解决了。

于 2010-12-22T16:59:41.737 回答
0

这发生在 VS 2008、2010 或 Expression Blend 中吗?VS2008 设计器是出了名的脆弱。至于修复它,您是否尝试过使用非泛型委托类型?像这样:

public delegate bool SendToDetail();

然后您的 VM 将公开该委托类型的属性,而不是Func<bool>.

于 2010-09-08T21:47:37.980 回答