New Posts New Posts RSS Feed: Dialog with buttons in the dialog content
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Dialog with buttons in the dialog content

 Post Reply Post Reply
Author
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Topic: Dialog with buttons in the dialog content
    Posted: 23-Mar-2012 at 5:26am
Hi,

we have the problem that we have to implement a dialog with custom locations for the dialogbuttons (in this case: in a ribbon bar). The buttons have to be in the containing dialog content. Is this possible with Cocktail's built-in DialogManager?

The only solution I can think of is to call _dialogManager.ShowDialog with an empty buttons-array and call the dialog's parent's close method, if the parent is typeof DialogHostBase. But i doubt that this is the right approach. I'd hope for something that smells less like a hacky workaround and is a bit more like a thorough framework implementation.

Thanks for your help in advance!

Best, Roland
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 23-Mar-2012 at 6:31am
Cocktail allows you to replace the ViewModel and View that make up the dialog window/popup with your own. Unfortunately, it's not documented yet.
 
You start by creating your own ViewModel and have it extend DialogHostBase. Then you create a corresponding view the way you want it to look. You can start with the XAML that Cocktail uses. Look for DialogHostView.xaml in the source code. Below is the Silverlight version.
 
In addition, you can define your own custom buttons by calling _dialogManager.ShowDialog with your own array of custom objects. Strings, images or whatever you want.
 
The buttons are outside of the containing dialog content, though, even if you do your custom view. Is there a reason they need to be in the containing content?
 
<controls:ChildWindow x:Class="Cocktail.DialogHostView"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:cal="http://www.caliburnproject.org"
                      xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      d:DesignHeight="277"
                      d:DesignWidth="800"
                      HasCloseButton="False"
                      mc:Ignorable="d">
 
    <Grid x:Name="LayoutRoot"
          MinWidth="166"
          Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
 
        <ItemsControl x:Name="DialogButtons" Grid.Row="1">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Width="75"
                            Height="23"
                            Margin="5"
                            cal:Message.Attach="Close($dataContext)"
                            Content="{Binding Content}"
                            IsEnabled="{Binding Enabled}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <ContentControl x:Name="ActiveItem"
                        Width="Auto"
                        Height="Auto"
                        HorizontalContentAlignment="Stretch"
                        VerticalContentAlignment="Stretch" />
    </Grid>
</controls:ChildWindow>
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Posted: 25-Mar-2012 at 11:32pm
Thanks for your quick answer!

But the problem is, that we need more buttons than the dialog-closing buttons in the ribbon. They need to be in the content view, because 1 - of the specs and 2 - usability. All interactions are limited to the ribbon bars in the views. In many cases we have quite heavy dialogs, containing eg. 5 buttons to interact - 4 to do stuff and interact with the view, 1 to close the dialog. If there is a ribbon bar (at the top), we can't introduce another area where the user can close the dialog.

Is there a way to close the dialog from the containing view(model)? I hoped for something like: The dialog host closes if the dialogcontentviewmodel is being closed, and the DialogResult is something like "ClosedByContent", so that the programmer knows that he has to check in the containing viewmodel instance for any values he needs. This would keep the containing VM independent from the host, but add the possibility to start the close-interaction from the containing VM.

I'm suggesting this, because I think that this might be a problem for others as well.

Thanks for your help (once again)!
Roland


Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Mar-2012 at 11:10am
The DialogManager is designed around the notion of a list of buttons that close the dialog. Each button corresponds to a dialog result, much like the standard MessageBox class. The DialogManager is designed to handle user prompts, not more complex ViewModels that handle their own user interaction.
 
The use case you are describing is demonstrated in the LoginViewModel in TempHire. It demonstrates the pattern for how to display your own custom ViewModels as a dialog. The DialogManager cannot add a lot of value here. I'll consider adding a ShowCustomDialog method or something like that to the DialogManager, which would handle the IResult implemetation for you, but in the meantime you can follow the pattern demonstrated by the LoginViewModel.
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 1:58am
Ok, just to know that I get this right, the steps to do are:

  • Create the dialog screen, that implements IResult;
  • The IResult.Execute just calls windowManager.ShowDialog(this);
  • The Completed event rises in the OnDeactivate method, if the close-bool is true;
  • In general: Use the CM-WindowManager instead of the Cocktail DialogManager;

I never considered making a screen an IResult. That opens my eyes!

Anyway, it would be nice to have a ShowCustomDialog method in the DialogManager, just for the sake of completeness.

Thanks again!

Best regards,

Roland

Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 10:25am
You got it. I'll look into the possiblity of adding a ShowCustomDialog method.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 09-Oct-2012 at 7:52am
Excuse me marcel,
can I just redefine the Cocktail.DialogHostView in my app and use my custom view? How can I do this?
Thanks
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 09-Oct-2012 at 8:39am
Yes, you can. It's explained above and also documented in the DRC now.
 
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 11:19pm
Hi Marcel, I'm afraid I'm a bit confused at the moment:
Following your link I know how I can change the DialogHost. But how do I get the DialogManager to use my CustomDialogHost as the default host?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 11-Oct-2012 at 8:23am
It will automatically discover it through MEF and use yours instead of the default.
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Posted: 11-Oct-2012 at 8:57am
Great. Very handy and easy to use. In my opinion, this would be worth mentioning in the docs!
Thanks! Roland
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 11-Oct-2012 at 9:30am
Yes, I updated the docs.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down