【问题标题】:DependencyProperty of Type Delegate类型委托的 DependencyProperty
【发布时间】:2011-04-09 19:31:21
【问题描述】:

我创建了一个附加行为,用于在调用行为时执行Func<bool> 类型的委托。下面是依赖属性定义。

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

我让它按预期工作,但是在我的 XAML 中出现以下错误,导致设计器无法加载。

属性“SendToDetailBehavior”原为 未找到或不可序列化 输入“SortableListView”

您将在下面找到 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">

例如,如果我将依赖属性的基础类型更改为bool,错误就会消失。

正如我所说的附加行为是有效的,只有设计者爆炸了。我一直在寻找这方面的文档,但结果却是空的。我希望这里有人有一些见解。

谢谢, 宽带网

【问题讨论】:

    标签: wpf dependency-properties attached-properties attachedbehaviors


    【解决方案1】:

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

    public delegate bool SendToDetail();
    

    然后您的 VM 将公开该委托类型的属性,而不是 Func&lt;bool&gt;

    【讨论】:

    • 我还没有厌倦那个。这是一个公平的建议,我会在早上尝试一下。可悲的是VS2008。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      相关资源
      最近更新 更多