This is a migrated thread and some comments may be shown as answers.

RadWindow using DataEventTrigger

1 Answer 71 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mark Shortt
Top achievements
Rank 1
Mark Shortt asked on 02 Aug 2011, 09:45 AM
Hi

I'm evaluating using RadWindow for our Silverlight  / MVVM project.

Is there a way to call the showDialog and Close events from XAML?

I'm looking to use a solution similar to the answer to the following question

http://stackoverflow.com/questions/1424202/how-can-i-have-a-wpf-eventtrigger-on-a-view-trigger-when-the-underlying-viewmodel/1996324#1996324


Thanks

Mark

1 Answer, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 04 Aug 2011, 11:51 AM
Hello Mark,

 The Window control is not designed to be placed in XAML so we designed its API to work from C# code using the Show/ShowDialog and Close methods. If you need a property which can open and close the Window you could create an attached one to do the work in its PropertyChanged callback. Please refer to the following example:

public static bool GetIsOpen(DependencyObject obj)
{
    return (bool)obj.GetValue(IsOpenProperty);
}
 
public static void SetIsOpen(DependencyObject obj, bool value)
{
    obj.SetValue(IsOpenProperty, value);
}
 
public static readonly DependencyProperty IsOpenProperty =
    DependencyProperty.RegisterAttached("IsOpen", typeof(bool), typeof(WindowTest), new PropertyMetadata(OnIsOpenPropertyChanged));
 
private static void OnIsOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var window = d as RadWindow;
 
    if (window != null)
    {
        if ((bool)e.NewValue)
        {
            window.Show();
            window.Closed += OnWindowClosed;
        }
        else
        {
            window.Closed -= OnWindowClosed;
            if (window.IsOpen)
            {
                window.Close();
            }
        }
    }
}
 
private static void OnWindowClosed(object sender, WindowClosedEventArgs e)
{
    SetIsOpen(sender as RadWindow, false);
}


Best wishes,

Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
Window
Asked by
Mark Shortt
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Share this question
or