Использование призмы в ElementHost - PullRequest
0 голосов
/ 26 марта 2012

Может кто-нибудь подсказать, чего может не хватать в следующем коде. У меня ничего не отображается на моем WinForm.

Я просмотрел следующие похожие посты на эту тему, но они не решили проблему для меня.

WinForm с ElementHost

    Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    '   WPF application instance
    _wpfApplication = Application.Current()

    If Application.Current Is Nothing Then
        _wpfApplication = New Application()
    End If

    '   Load the application modules
    Dim unityBootstrapper As New Bootstrapper()
    unityBootstrapper.Run()

    '   Bind the shell to the ElementHost
    Dim shellElement = unityBootstrapper.Container.Resolve(Of Shell)()
    ehMaster.Child = shellElement

End Sub

Загрузчик

Public NotInheritable Class Bootstrapper
Inherits UnityBootstrapper

Protected Overrides Function CreateShell() As DependencyObject
    Return New Shell
End Function

Protected Overrides Function GetModuleCatalog() As IModuleCatalog
    Dim catalog As ModuleCatalog = New ConfigurationModuleCatalog()
    catalog.AddModule(GetType(Pitchbook.Excel.ChartWizardModule))
    Return catalog
End Function

End Class

Shell

<UserControl x:Class="Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF">
<DockPanel>
    <ItemsControl x:Name="HeaderRegion" cal:RegionManager.RegionName="HeaderRegion" DockPanel.Dock="Top" Height="auto">

    </ItemsControl>
    <ItemsControl x:Name="LeftRegion" cal:RegionManager.RegionName="LeftRegion" Width="auto" DockPanel.Dock="Left">

    </ItemsControl>
    <ItemsControl x:Name="MainRegion" cal:RegionManager.RegionName="MainRegion" DockPanel.Dock="Bottom">

    </ItemsControl>
</DockPanel>
</UserControl>

Partial Public Class Shell
Inherits UserControl

Public Sub New()
    InitializeComponent()
End Sub

End Class

ChartWizardModule

Public NotInheritable Class ChartWizardModule
Implements IModule

Private ReadOnly regionManager As IRegionManager

Public Sub Initialize() Implements IModule.Initialize
    regionManager.RegisterViewWithRegion("MainRegion", GetType(Test))
End Sub

Public Sub New(regionManager As IRegionManager)
    Me.regionManager = regionManager
End Sub

End Class

1 Ответ

0 голосов
/ 27 марта 2012

Я не уделил достаточно внимания этому посту Как использовать Prisim в ElementHost

Проблема в том, что вам нужен Application.Current, который не равен нулю, а не равен typeof (Application) .

Поэтому я создал следующий класс

Public Class WpfApplicationAdapter
    Inherits Windows.Application

    '   HACK - This class shouldn't be required. Look out for a resolution to this in future WPF versions.

End Class

И изменил мой конструктор WinForm на следующий

    Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    If Application.Current Is Nothing Then
        Dim wpfAppAdapter As New WpfApplicationAdapter
    End If

    '   Load the application modules
    Dim formBootstrapper As New Bootstrapper
    formBootstrapper.Run()

    '   Get the current instance of shell and bind it to the ElementHost
    Dim shellElement = formBootstrapper.Container.Resolve(Of Shell)()
    ehMaster.Child = shellElement

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...