Closing RadWindow Using DialogResult

4 posts, 0 answers
  1. Carlos
    Carlos avatar
    29 posts
    Member since:
    Jun 2010

    Posted 08 Feb 2014 Link to this post


    I'm trying to close a RadWindow from my view model. I've bound DialogResult to my view model but setting it doesn't seem to close the window.

    Is there something I'm missing or does the RadWindow only support being closed by calling it's Close event?

    Any help would be appreciated.
  2. Polya
    Polya avatar
    191 posts

    Posted 12 Feb 2014 Link to this post

    Hi Carlos,

    The DialogResult can be used from the code that showed a modal RadWindow to determine whether a user accepted or canceled it. In other words this property returns the user input into the modal DialogResult which does not correspond to whether the RadWindow is Closed or Opened.

    To open or close a RadWindow we should call the Show() and Close() methods. I suggest referring to this article for information on how to Close a RadWindow through its content.

    Hopefully this helps.


    Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

  3. DevCraft banner
  4. Lance Benger
    Lance Benger avatar
    2 posts
    Member since:
    Oct 2012

    Posted 18 Feb 2014 in reply to Polya Link to this post

    Hi Carlos

    I found some code on the net that does it.
    Create this class;

    using System.Windows;
    using Telerik.Windows.Controls;

    namespace FwWPFUIControls.Utility
        public static class RadWindowDialogCloser
            public static void SetDialogResult(RadWindow radWindow, bool? value)
                if (radWindow != null)
                    radWindow.SetValue(RadWindow.DialogResultProperty, value);
                    if (value != null) radWindow.Close();

            public static bool? GetDialogResult(RadWindow radWindow)
                if (radWindow != null)
                    return radWindow.GetValue(BindableDialogResultProperty) as bool?;
                return null;

            public static readonly DependencyProperty BindableDialogResultProperty = DependencyProperty.RegisterAttached("DialogResult", typeof (bool?), typeof (RadWindowDialogCloser), new PropertyMetadata(BindableDialogResultPropertyChanged ));

            private static void BindableDialogResultPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
                SetDialogResult(d as RadWindow, e.NewValue as bool?);

    then in the header of your RadWindow put this;

                 xc:RadWindowDialogCloser.DialogResult="{Binding DialogResult}"

    then in your viewmodel put this;

            private bool? _dialogResult;

            public bool? DialogResult
                get { return _dialogResult; }
                set { CheckPropertyChanged(ref _dialogResult, ref value); }

    (the CheckPropertyChanged function is my implementation of IPropertyNotifyChanged - so use yours or I can send you mine)

    Then when you need to close the form set the DialogResult to true or false and the form will close.

    Actually here is the post I found it on;
  5. pavan
    pavan avatar
    1 posts
    Member since:
    May 2014

    Posted 01 Aug 2014 in reply to Lance Benger Link to this post


    I used this above code and it works like a charm. The only issue that I have is, I see an error in the error list lingering. The error says: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Nullable`1[System.Boolean]'

    I am thinking that since we are building the DependencyProperty during runtime, by calling DependencyProperty.RegisterAttached, the design time Visual Studio UI builder doesnt know that this is a valid Dependency Property, and hence the error. Can anyone confirm that I am understanding it correctly?
Back to Top