send data to the dialog

Topics: Actions & Coroutines
Sep 21, 2012 at 5:18 PM

hi. and sorry for the noobness, i'm fairly new to the framework, but i'm beginning to understand it and it's inner works.

my question is this. i using caliburn micro 1.3.1 and trying to send some data to a dialog, but i don't have the faintest idea on how to do this.

for the creation of the dialog i used this thread and it works without any problems.

but now i'm lost on how to set the value of the message of the dialog?

help would be appreciated

thanks in advance

Sep 22, 2012 at 11:42 PM

i've been trying several other approaches but none work.

can anyone give me some pointers on how do i set this property? for you guys a no brainer. for me a complex task.

what i would like to do is the following.

the shellview recieves an event, from something that happened on a view, logs the problem and shows a dialog informing the user that something wrong happened.

i can show the dialog. but i can't set the message of the dialog.

 

help would be appreciated

Coordinator
Sep 23, 2012 at 6:58 PM

You just need to have a property on your dialog view model that you can set to whatever message you want. That should be bound to the UI...and you are done.

Sep 23, 2012 at 11:00 PM

this is the code for my dialog view model:

using System.ComponentModel.Composition;
using System.Windows;
using Caliburn.Micro;
namespace testeCaliburn.ViewModels
{
    [Export(typeof(MessageBoxViewModel))]
    public class MessageBoxViewModel:Screen
    {

        private string _message;
        public string Message
        {
            get { return _message; }
            set
            {
                _message = value;
                NotifyOfPropertyChange(() => Message);
            }
        }



        private string _messageboxtitle;
        public string MessageTitle
        {
            get { return _messageboxtitle; }
            set
            {
                _messageboxtitle = value;
                NotifyOfPropertyChange(() => MessageTitle);
            }
        }

    }
}

 

this is the code for the dialog view

<Window x:Class="testeCaliburn.Views.MessageBoxView"
        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:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Height="300" Width="300"
        cal:Message.Attach="[Event Load]=[Action LoadEvent]">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Label Content="{Binding Path=MessageTitle}"/>
        <!-- <TextBlock Grid.Row="1" Text="{Binding Path=MessageboxMessage}" TextWrapping="Wrap" Margin="6,6,0,0"/>-->
        <TextBlock x:Name="Message" TextWrapping="NoWrap" Margin="6,6,0,0"/>
    </Grid>
</Window>


this is my shellViewModel:
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Caliburn.Micro;

using testeCaliburn.Models;
namespace testeCaliburn.ViewModels
{
   
    [Export(typeof(IShell))]
    public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
    {
       
        public IEnumerable<IResult>ShowModal()
        {

            var tmpModel = new MessageBoxViewModel();
            
            var openD = ShowDialog.Of< MessageBoxViewModel>();
            yield return openD;

        } 
        private string title;
        public string Title
        {
            get { return title; }
            set
            {
                if (title != value)
                {
                    title = value;
                    RaisePropertyChangedEventImmediately("Title");
                }
            }
        }

        #region Ctor
        [ImportingConstructor]
        public ShellViewModel(MessageBoxViewModel valueMessage)
        {

            Title = "Hello Caliburn.Micro";
            //EventAggregator = valueEventAgregator;
            Items.Add(valueMessage);
            

           
        }
        #endregion

    }
}


and the show dialog code:

using System;
using System.ComponentModel.Composition;
using Caliburn.Micro;
namespace testeCaliburn.Models
{
    public class ShowDialog:IResult
    {
        private readonly Type screenType;
        private readonly string _name;
        public object Dialog { get; private set; }
       
        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
        [Import]
        public IWindowManager Window { get; set; }

        public ShowDialog(string valuename)
        {
            _name = valuename;
        }
        public ShowDialog(Type valueType)
        {
            screenType = valueType;
        }

        public static ShowDialog Of<T>() 
        {
            return new ShowDialog(typeof(T));
        }

        #region Implementation of IResult

        public void Execute(ActionExecutionContext context)
        {
            var screen = !string.IsNullOrWhiteSpace(_name) ? IoC.Get<object>(_name) : IoC.GetInstance(screenType, null);

            Dialog = screen;
          
            Window.ShowDialog(screen);
            var _deactivated = screen as IDeactivate;
            if (_deactivated==null)
            {
                Completed(this,new ResultCompletionEventArgs());
            }
            else
            {
                _deactivated.Deactivated += (o, e) =>
                                                {
                                                    if (e.WasClosed)
                                                    {
                                                        Completed(this, new ResultCompletionEventArgs());
                                                    }
                                                };
            }
        }

       
     
        #endregion
    }
}

they are connected or so i believe. i've used this formula always and it's working. caliburn connects the both of them. where in the invocation. where does the message enters in this picture?

thanks