skinning a window

Topics: Prism v2 - WPF 3.5
Jul 19, 2009 at 5:20 PM

I may be understanding incorrectly.

I have a WPF application with the following:

Bootstraper.vb

<font size="2">

 

</font>

  Protected Overrides Function CreateShell() As System.Windows.DependencyObject
        Dim shell As Shell = Container.Resolve(Of Shell)()
        shell.Content = Container.Resolve(Of ShellPresentationModel)()
        shell.Show()
        Return shell
    End Function

Shell.xaml

 

 

<font size="2" color="#0000ff">

 

</font>

ShellPresentationModel.vb

 

Public Class ShellPresentationModel

#Region "Fields"
    Private _mainRegion As New Region
    Private _globalCommandsRegion As New Region
#End Region

#Region "Properties"
    Public Property MainRegion() As Region
        Get
            Return _mainRegion
        End Get
        Set(ByVal value As Region)
            _mainRegion = value
        End Set
    End Property

    Public Property GlobalCommandsRegion() As Region
        Get
            Return _globalCommandsRegion
        End Get
        Set(ByVal value As Region)
            _globalCommandsRegion = value
        End Set
    End Property
#End Region

    Public Sub New(ByVal regionManager As IRegionManager)
        regionManager.Regions.Add("MainRegion", _mainRegion)
        regionManager.Regions.Add("GlobalCommandsRegion", _globalCommandsRegion)
    End Sub

End Class

ResourceDictionary.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FinanceManager">
    <DataTemplate DataType="{x:Type local:ShellPresentationModel}">
</DataTemplate>
</ResourceDictionary>

 The code thus far comes from the commanding qs.

I want to completely change the style of the window. I will need to handle minimize, maximize, exit and drag events for the window. I put the xaml for the buttons in ResourceDictionary.xaml. I ran into a snag when I went to write the code in ShellPresentationModel.vb. ShellPresentationModel doesn't know about the window. Should I even be trying to skin the window this way? If so, how do I gain access to the current window in ShellPresentationModel?

Jul 20, 2009 at 7:44 PM

Hi 

Are you using the Prism Visual Basic release in your code? The code I have in the CommandingBootstrapper is:
Protected Overrides Function CreateShell() As DependencyObject
        Dim shell = Container.Resolve(Of Shell)()
#If SILVERLIGHT Then
        Application.Current.RootVisual = shell
#Else
        shell.Show()
#End If
        Return shell
End Function

The usual approach when using Dependency Injection and resolving a UI component and its Presenter/ViewModel is resolving one of them and injecting the other. For example, you could simply resolve the Shell, which gets its ViewModel through constructor injection and set it as the DataContext (not the Content). In this scenario, the CreateShell method would look like the one above. You can also set a property in the ViewModel that keeps a reference to the Shell window, which is the goal of all this. The following code could be in the Shell’s constructor:

Public Sub New(ByVal model As ShellPresentationModel)

        Me.DataContext = model

        model.View = Me

End Sub

 

You might find useful as a starting point the Reference Implementation that uses a presenter for the Shell and uses Styles to skin the popup windows. There is also a good post from Julian Dominguez, Presentation Model with DataTemplates in CompositeWPF (Prism) Sample, that provides a sample of the commanding quickstart (of Prism v1) modified to use DataTemplates.

 

You might find useful the following topics of the Unity documentation:

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman