Actions not shown

Apr 20, 2015 at 2:42 PM
I have a existing application and want to use the CODe Framework for a module of this application (in future time i will adapt the whole application to use CODE Framework - but now I will start with a little step)

Here the code of my View
<mvvm:View x:Class="ManagementView"
             Style="{DynamicResource CODE.Framework-Layout-SimpleFormLayout}" >

                <ResourceDictionary Source="/CODE.Framework.Wpf.Theme.Workplace;component/ThemeRoot.xaml"/>
    <di:DisplayLabel mvvm:View.GroupBreak="True" mvvm:View.GroupTitle="Allgemeines" Target="{Binding ElementName=txtName}" />
    <TextBox mvvm:View.WidthEx="20" Text="{Binding Current.Name, UpdateSourceTrigger=PropertyChanged}" Name="txtName"/>

The Code-Behind of the View is:
  Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Me.DataContext = New ApplicationViewModels.ManagementViewModel

    End Sub
The ModelView is shown below (only the important part with the action definition):
Partial Class ManagementViewModel

    Inherits CODE.Framework.Wpf.Mvvm.ViewModel
    Implements IHaveActions

#Region "Init"

    Public Sub New()


            ' Erzeugt die benötigten Aktionen

        Catch ex As Exception
        End Try

    End Sub

#End Region

#Region "Actions"

    Private Sub GenerateActions()

        NLOGLOGGER.Info("Generate List of Default Actions")

        Dim newAction As New ViewAction("Neu")
        With newAction
            '.ViewActionType = ViewActionTypes.Standard
            '.Significance = ViewActionSignificance.AboveNormal
            '.Visibility = Visibility.Visible
            '.BrushResourceKey = "CODE.Framework-Icon-New"
            .Execute(Sub(action, param) Controller.Message(action.Caption, , MessageBoxButtons.OK))
        End With

        Dim saveAction As New ViewAction("Speichern")
        With saveAction
            '.ViewActionType = ViewActionTypes.Standard
            '.Significance = ViewActionSignificance.AboveNormal
            '.Visibility = Visibility.Visible
            '.BrushResourceKey = "CODE.Framework-Icon-Save"
            .Execute(Sub(action, param) Controller.Message(action.Caption, , MessageBoxButtons.OK))
        End With

        Dim deleteAction As New ViewAction("Löschen")
        With deleteAction
            '.ViewActionType = ViewActionTypes.Standard
            '.Significance = ViewActionSignificance.AboveNormal
            '.Visibility = Visibility.Visible
            '.BrushResourceKey = "CODE.Framework-Icon-Delete"
            .Execute(Sub(action, param) Controller.Message(action.Caption, , MessageBoxButtons.OK))
        End With


       NLOGLOGGER.Info("Summary: " & Actions.Count & " Action(s) defined")

    End Sub

#End Region

I want to add buttons like the login-Form of the ViewExample. What is missing? How can give me a hint or can help me?
Apr 22, 2015 at 5:58 PM

CODE Framework uses a style for the UI container. (That style is typically found in one of the Shell XAML files in each theme resource). These styles don't just host the view, but the also inspect the current view-model to see if it implements IHaveActions, and if so, the actions are displayed in whatever form the style defines (such as a bar of buttons at the top or something like that).

So to make this work in another framework and have the actions automatically included, you would have to replicate this setup somehow. It's not rocket science, but it needs to be added there. I am not sure where your view is currently being hosted (such as in a Window or somewhere else).

The following for instance, is the style Metro uses to host a view (which the Metro theme does in a tab control):
    <Style TargetType="mc:ShellTabControl" x:Key="CODE.Framework.Wpf.Mvvm.Shell-NormalViewsHost" >
        <Setter Property="Background" Value="{x:Null}"/>
        <Setter Property="BorderBrush" Value="{x:Null}"/>
        <Setter Property="ContentTemplate">
                    <Grid c:GridEx.RowHeights="*,Auto">
                            <ContentControl Content="{Binding View}" />
                        <mvvm:ActionGrid Grid.Row="1" Model="{Binding Model}">
                            <mvvm:ActionItemsControl Model="{Binding Model}" HorizontalAlignment="Right" Margin="10,5,10,0" IsTabStop="false">
                                        <Button x:Name="toolbarButton"
                                                Style="{DynamicResource Metro-Control-AppBarButtonStyle}"
                                                Content="{Binding Caption}" Command="{Binding}" 
                                                IsDefault="{Binding IsDefault, Mode=OneWay}" IsCancel="{Binding IsCancel, Mode=OneWay}">
                                        <StackPanel Orientation="Horizontal" />
I removed a few details there to keep this as simple as possible, but this captures the general idea: The container that hosts the view (which is a content control kind of object) has this template, which includes a content control that displays the actual view. In addition, there is a CODE Framework helper object (which you can use, but it isn't a requirement) that binds to the Model. This element is called ActionGrid. The main attribute of this object is that is hides itself if the Model doesn't implement IHaveActions, so it is very convenient for this task. If the Model does indeed have actions, this grid is shown and inside of itself there is another CODE Framework helper object called ActionItemsControl, which auto-populates itself from actions defined on the model object. All that is left to do at this point is to define what these actions look like by creating an item template that gets applied to each (this example uses a Button).