Wpf:在哪里存储附加属性中使用的帮助器类?
我想在工具栏托盘中使用数据绑定,所以我创建了一些服务和附加属性来满足我的需要。最终的解决办法是:Wpf:在哪里存储附加属性中使用的帮助器类?,wpf,Wpf,我想在工具栏托盘中使用数据绑定,所以我创建了一些服务和附加属性来满足我的需要。最终的解决办法是: <ToolBarTray local:TrayBinding.ItemsSource="{Binding Path=Groups}" local:TrayBinding.ToolBarItemsSource="Items"></ToolBarTray> ToolBarTrayBinder存储在私有依赖项属性中: priva
<ToolBarTray local:TrayBinding.ItemsSource="{Binding Path=Groups}"
local:TrayBinding.ToolBarItemsSource="Items"></ToolBarTray>
ToolBarTrayBinder存储在私有依赖项属性中:
private static readonly DependencyProperty BindingServiceProperty = DependencyProperty.Register("TrayBinder",
typeof(ToolBarTrayBinder),
typeof(ToolBarTray),
new PropertyMetadata(null));
因此,我的问题是:在附加属性的项上添加帮助器类(如ToolBarTrayBinder)作为依赖属性是否被认为是一种良好的做法?在执行此操作时是否存在任何问题,例如内存泄漏或类似问题会导致问题?我看不出这有什么问题,尽管简单地关联数据(仅关联数据,而不使用数据绑定或更新通知)有点重使用简单的字典缓存会稍微减少开销,但如果工具栏托盘消失,使用DP确实会让您受益于DP消失的好处(因为DependencyObject提供了存储。)我看不出这有什么问题,尽管简单地关联数据有点重(您只关联数据,不使用数据绑定或更新通知。)简单的字典缓存的开销稍小,但如果工具栏托盘消失,使用DP确实会使DP消失(因为DependencyObject提供存储)这就是为什么我首先选择依赖性属性,因为我想用工具栏托盘存储帮助器类。这就是为什么我选择依赖性属性,因为我想用工具栏托盘存储帮助器类。
private static readonly DependencyProperty BindingServiceProperty = DependencyProperty.Register("TrayBinder",
typeof(ToolBarTrayBinder),
typeof(ToolBarTray),
new PropertyMetadata(null));