DataWindow with "submit" button (SL4)

Dec 21, 2011 at 9:15 PM

Using SL4. 

I have a model and view model and want to use the UIVisualizerService to show a DataWindow for this view model, but not with the standard buttons, but with a single "submit" button.

When the "submit" button is clicked, a view model method that submits the model to a service should be called and if this is successful, the DataWindow should close.

Can you give me some hints of how to achieve this?

Dec 22, 2011 at 1:48 PM

It is possible to use custom buttons and still be able to use the DataWindow.

1. First, use the base constructor to specify that you want to use custom mode.

 

/// <summary>
/// Upload window.
/// </summary>
public class UploadWindow : Window<UploadViewModel>
{
    public UploadWindow()
        : base(DataWindowMode.Custom)
    {
        InitializeComponent();
    }
}

 

2. Add the custom buttons. This must be done before the call to InitializeComponent.

 

/// <summary>
/// Upload window.
/// </summary>
public class UploadWindow : Window<UploadViewModel>
{
    public UploadWindow()
        : base(DataWindowMode.Custom)
    {
        AddCustomButton(new DataWindowButton("Upload", "Upload"));

        InitializeComponent();
    }
}

If you are using Silverlight and intermediate classes, you can implement this in your intermediate class.

 

Dec 24, 2011 at 11:07 AM

Thanks for the clear explanation.

The only thing I need to figure out now is the best way to close the dialog from the "Upload" method. Will check the documentation for this.

Dec 24, 2011 at 11:44 AM

just call CloseViewModel and the magic will occur. the view keeps track of the vm, and if the vm is closed, so is the view.