Using a datawindow for feedback to the user.

Feb 14, 2012 at 3:12 PM

Hello

We are trying to implement a DataWindow in my application. When exporting, We would like to show what we've done and give some feedback to the user.
So we've managed to show the DataWindow and put some content in, but we want to change some buttons.

We've checked the documentation but we only found where to use custombuttons, but the standard "close" button is good enough for us, but we don't know how to activate that one and hide the cancel/save options. Here is our setup:

<Item:ExportToExcelViewIntermediate 
    x:Class="ItemManagementTool.ClientApplication.Views.Item.ExportToExcelView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Item="clr-namespace:ItemManagementTool.ClientApplication.Views.Item"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="{StaticResource MainPageBackground}" MinWidth="400" MinHeight="200">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock Text="This is just to show I can do this" Margin="5"/>
        <Image Source="/ItemManagementTool.ClientApplication;component/Resources/Images/check.png" Margin="5" >
            <ToolTipService.ToolTip>
                <ToolTip Content="{Binding Path=LockToolTip}"></ToolTip>
            </ToolTipService.ToolTip>
        </Image>
    </Grid>
</Item:ExportToExcelViewIntermediate>

code-behind

Namespace Views.Item
    ''' <summary>
    ''' Dummy class because Silverlight doesn't allow generic user controls.
    ''' </summary>
    Public Class ExportToExcelViewIntermediate
        Inherits DataWindow(of ViewModels.Item.ExportToExcelViewModel)
    End Class

    ''' <summary>
    ''' Gives feedback to the user of what the result of the export is and where the export was placed.
    ''' </summary>
    Partial Public Class ExportToExcelView
        Inherits ExportToExcelViewIntermediate
        ''' <summary>
        ''' Initializes a new instance of the <see cref="ExportToExcelView"/> class.
        ''' </summary>
        Public Sub New()
            InitializeComponent()
        End Sub

    End Class
End Namespace

And the ViewModel:

Namespace ViewModels.Item
    Public Class ExportToExcelViewModel
        Inherits IMTW.UI.ViewModelBase

    End Class
End Namespace

We are calling the datawindow like this:

Dim uiVisualizerService = GetService(Of IUIVisualizerService)()
uiVisualizerService.Unregister(GetType(ViewModels.Item.ExportToExcelViewModel))
uiVisualizerService.Register(GetType(ViewModels.Item.ExportToExcelViewModel), GetType(Views.Item.ExportToExcelView))
uiVisualizerService.ShowDialog(New ViewModels.Item.ExportToExcelViewModel())

Any hints on how we can tweak the Datawindow so we see just a close button?

Coordinator
Feb 14, 2012 at 4:27 PM

Inside the DataWindow constructor, when calling the base, simply call DataWindowMode.Close.

Feb 15, 2012 at 9:51 AM

Thanks for that, worked like a charm.

Seems I'm gonna use a custom button, for styling matters.
The button invokes an event, but calling the MyBase.Close doesn't close the viewModel I'm working with.

This is how I try to do it (in my viewmodel).

 

Private Sub InitPage()
    CloseCommand = New Catel.MVVM.Command(AddressOf OnClose)
End Sub

Private Sub OnClose()
    MyBase.Close()
End Sub

The Xaml:
<Image Source="/ItemManagementTool.ClientApplication;component/Resources/Images/check.png" Grid.Row="1" Grid.Column="1">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <catel:EventToCommand Command="{Binding CloseCommand}" DisableAssociatedObjectOnCannotExecute="False" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ToolTipService.ToolTip>
        <ToolTip Content="{Binding Source={StaticResource Dictionary}, Path=LocalizedStrings.ItemExportFeedbackTooltip}" />
    </ToolTipService.ToolTip>
</Image>

Any thoughts?

 

Coordinator
Feb 15, 2012 at 8:13 PM

You might want to try setting the DialogResult. Strange that Close (on the view I assume) doesn't close the view model, we should look after this. You know you can also add custom buttons to the bottom of the page using AddCustomButton?

We are currently working very hard on 3.0, the data window will then be fully stylable. If you are interested in joining the early bird beta acces, please let us know.

Feb 16, 2012 at 6:32 AM

The Close is invoked on the view with an eventToCommand, as you can see in my previous post. Is there any other way I can close the datawindow in the view?

As my intermediate view inherits from datawindow in the codebehind, I'm not sure I can access datawindow specific issues in the xaml of the view.

 

Concerning the custom buttons, I don't think this case needs a custom behavior, it just needs to close the datawindow.

Feb 20, 2012 at 2:35 PM

As I still don't get the Close command to work, I'll try using the standard close Button, but then I would like to restyle it.

I've seen there's a DataWindowButtonStyle attribute on the DataWindow, but I'm not sure how to address it.
In the codebehind, I tell me intermediate it inherits from DataWindow, but in  XAML, I can't apply the style, it keeps saying the intermediate doesn't have that attribute.

Am I missing something?

Coordinator
Feb 22, 2012 at 6:53 AM

Sorry, I didn't know there was still a question open on this thread.

1) You can call CloseViewModel on the view, and then the view doesn't close? Make sure that the Save() method returns true, otherwise the window will not be closed.

2) The DataWindowButtonStyle is for all buttons. In Catel 3.0, we are working on a "per-button" customization of the styles, but in Catel < 3.0, you will have to restyle the DataWindowButtonStyle (which is just a style which is retrieved at runtime). In your data window resources, you can use something like this:

    <Style x:Key="DataWindowButtonStyle" TargetType="Button">
        <Setter Property="Margin" Value="6, 6, 0, 0" />
        <Setter Property="HorizontalAlignment" Value="Right" />
        <Setter Property="MinWidth" Value="100" />
        <Setter Property="MinHeight" Value="23" />
    </Style>

Feb 22, 2012 at 7:15 AM

Thank you for your reply.

1) I'm not sure what the Save() method has to do here? I don't call any save method, unless that's what the Close() method does behind the scenes.

2) The problem with the style is not how to create the style, but how to apply it. The close button isn't created in XAML in my intermediate view, and I also don't have a DataWindow in XAML, as you can see in my first post.

Coordinator
Feb 22, 2012 at 7:27 AM

1) If you call CloseViewModel on your view model, it will save the view model and then close it. From inside your view model, you can call CloseAndSaveViewModel. I have double checked, but there is no close command. What you can do is add a close command to your view model, and then call this inside your command:

SaveAndCloseViewModel();

2) Your ExportToExcelViewIntermediate is your data window xaml.

Feb 22, 2012 at 7:45 AM

I could say Mybase.Close() in my viewmodel, but that didn't do the job.

I now tried SaveAndCloseViewModel, and it works like a charm.

May 2, 2012 at 12:45 PM

I remembered I posted something about the datawindow before, so I thought it was a good idea to continue here.

With the move to 3.0, I'm switching the intermediate classes, and using the datawindow like I see in the documentation on catenalogic.

Now we're having on issue, and we're not sure if it's code-related (c# to vb.net translation) or if it's something else. 

So we had this intermediate class in codebehind:

Namespace Views.Item
    ''' <summary>
    ''' Dummy class because Silverlight doesn't allow generic user controls.
    ''' </summary>
    Public Class ExportToExcelViewIntermediate
        Inherits DataWindow(of ViewModels.Item.ExportToExcelViewModel)
    End Class

    ''' <summary>
    ''' Gives feedback to the user of what the result of the export is and where the export was placed.
    ''' </summary>
    Partial Public Class ExportToExcelView
        Inherits ExportToExcelViewIntermediate
        ''' <summary>
        ''' Initializes a new instance of the <see cref="ExportToExcelView"/> class.
        ''' </summary>
        Public Sub New()
            InitializeComponent()
        End Sub

    End Class
End Namespace

And we're going to this form:

Imports FI = Framework.Infrastructure
Imports Catel.Windows

Namespace Views.Item
    ''' <summary>
    ''' Gives feedback to the user of what the result of the export is and where the export was placed.
    ''' </summary>
    Partial Public Class ExportToExcelView
        Inherits DataWindow

        Public Sub New(ByVal exportToExcelViewModel As ViewModels.Item.ExportToExcelViewModel)
            MyBase.New(exportToExcelViewModel)
            InitializeComponent()
        End Sub
    End Class
End Namespace

Now, the problem is situated in the MyBase.New() it gives this error:

'.ctor' is ambiguous because multiple kinds of members with this name exist in class 'Catel.Windows.DataWindow'.

Any idea if this is c#/vb.net related or is it something we're missing?

Coordinator
May 2, 2012 at 12:51 PM

We have moved to overloads instead of declaring every method and introducing a new parameter. It might be possible that optional parameters are not supported in VB.NET (not really good with VB.NET though).

Try specifying all parameters to see what happens.

May 2, 2012 at 1:08 PM

This doesn't influence the error, it's as if it doesn't validate what's between brackets

There error line just indicates MyBase.New, everything that comes behind it isn't included in the error.

PS.: vb.net do support optional parameters, so that's no problem.

Coordinator
May 2, 2012 at 2:20 PM

Yes, I mean, call MyBase.New() with all it's parameters.

May 2, 2012 at 2:32 PM

We tried:

MyBase.New(exportToExcelViewModel, DataWindowMode.Custom, Nothing, DataWindowDefaultButton.Close, False, InfoBarMessageControlGenerationMode.None)

(ctor overload seen on http://catel.catenalogic.com/index.html?t_catel_windows_datawindow.htm)

Still gives the same error, as well as the other overloads.

Coordinator
May 2, 2012 at 3:00 PM

It seems there is an issue with VB.NET and empty constructor overloads (1 empty, required for design time support, and 1 with all optional parameters). I just committed a fix.