This project is read-only.

Actions not shown

Apr 20, 2015 at 3: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"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:di="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
             xmlns:layout="clr-namespace:CODE.Framework.Wpf.Layout;assembly=CODE.Framework.Wpf"
             xmlns:controls="clr-namespace:CODE.Framework.Wpf.Controls;assembly=CODE.Framework.Wpf"
             xmlns:mvvm="clr-namespace:CODE.Framework.Wpf.Mvvm;assembly=CODE.Framework.Wpf.Mvvm"
             Style="{DynamicResource CODE.Framework-Layout-SimpleFormLayout}" >

    <mvvm:View.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/CODE.Framework.Wpf.Theme.Workplace;component/ThemeRoot.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </mvvm:View.Resources>
    <Grid>
    <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"/>

    </Grid>
</mvvm:View>
The Code-Behind of the View is:
  Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' 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()

        Try

 
            ' Erzeugt die benötigten Aktionen
            GenerateActions()


        Catch ex As Exception
            NLOGLOGGER.Fatal(ex.Message)
            Console.WriteLine(ex.Message)
        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))
            .CanExecute(CanNewCommand)
        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))
            .CanExecute(CanModifyCommand)
        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))
            .CanExecute(CanDeleteCommand)
        End With

        Actions.Add(newAction)
        Actions.Add(saveAction)
        Actions.Add(deleteAction)

       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 6:58 PM
Hello!

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">
            <Setter.Value>
                <DataTemplate>
                    <Grid c:GridEx.RowHeights="*,Auto">
                        <AdornerDecorator>
                            <ContentControl Content="{Binding View}" />
                        </AdornerDecorator>
                        <mvvm:ActionGrid Grid.Row="1" Model="{Binding Model}">
                            <mvvm:ActionItemsControl Model="{Binding Model}" HorizontalAlignment="Right" Margin="10,5,10,0" IsTabStop="false">
                                <mvvm:ActionItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Button x:Name="toolbarButton"
                                                Style="{DynamicResource Metro-Control-AppBarButtonStyle}"
                                                Content="{Binding Caption}" Command="{Binding}" 
                                                IsDefault="{Binding IsDefault, Mode=OneWay}" IsCancel="{Binding IsCancel, Mode=OneWay}">
                                        </Button>
                                    </DataTemplate>
                                </mvvm:ActionItemsControl.ItemTemplate>
                                <mvvm:ActionItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </mvvm:ActionItemsControl.ItemsPanel>
                            </mvvm:ActionItemsControl>
                        </mvvm:ActionGrid>
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
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).


Markus