gpt4 book ai didi

Prism:在一个区域中堆叠控件?

转载 作者:行者123 更新时间:2023-12-03 18:11:32 25 4
gpt4 key购买 nike

我的 Prism 应用程序需要将几个模块中的按钮插入外壳区域。按钮将垂直堆叠,就像 Outlook 2010 中的导航按钮(邮件、日历等)。我使用自定义控件作为按钮,所以我不需要担心模板——我的问题与如果我插入普通的单选按钮。

如何设置区域以使按钮垂直堆叠?谢谢你的帮助。

最佳答案

当考虑垂直堆叠项目时,StackPanel 会立即跳入脑海。不幸的是,Prism 不支持 StackPanel 成为开箱即用的区​​域。幸运的是,您可以创建一个 RegionAdapter 来解决这个问题。

Public Class StackPanelRegionAdapter
Inherits RegionAdapterBase(Of StackPanel)

Public Sub New(ByVal behaviorFactory As IRegionBehaviorFactory)
MyBase.New(behaviorFactory)
End Sub

Protected Overrides Sub Adapt(ByVal region As IRegion, ByVal regionTarget As StackPanel)
AddHandler region.Views.CollectionChanged, Sub(sender As Object, e As NotifyCollectionChangedEventArgs)
If e.Action = NotifyCollectionChangedAction.Add Then
For Each element As FrameworkElement In e.NewItems
regionTarget.Children.Add(element)
Next
Else
If e.Action = NotifyCollectionChangedAction.Remove Then
For Each element In e.OldItems
If regionTarget.Children.Contains(element) Then
regionTarget.Children.Remove(element)
End If
Next
End If
End Sub
End Sub

Protected Overrides Function CreateRegion() As Microsoft.Practices.Prism.Regions.IRegion
Return New AllActiveRegion
End Function
End Class

从那里您只需在 Bootstrap 的 ConfigureRegionAdapterMappings Override 中添加映射。

Protected Overrides Function ConfigureRegionAdapterMappings() As Microsoft.Practices.Prism.Regions.RegionAdapterMappings
Dim mappings = MyBase.ConfigureRegionAdapterMappings()
mappings.RegisterMapping(GetType(Grid), Container.Resolve(Of PrismExtensions.GridRegionAdapter))
mappings.RegisterMapping(GetType(StackPanel), Container.Resolve(Of PrismExtensions.StackPanelRegionAdapter))
Return mappings
End Function

编辑:找到我最初从中获取代码的 John Papa 链接。 (在 C# 中,如果你正在使用) Fill My Prism Region, Please

关于Prism:在一个区域中堆叠控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4950464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com