Hi,
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.
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.
3 Answers, 1 is accepted
0
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.
Regards,
Polya
Telerik
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.
Regards,
Polya
Telerik
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).
0
Lance B
Top achievements
Rank 2
answered on 18 Feb 2014, 05:02 PM
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;
xmlns:xc="clr-namespace:FwWPFUIControls.Utility;assembly=FwWPFUIControls"
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;
http://lensbjerg.wordpress.com/2012/06/19/close-telerik-radwindow-from-viewmodel-with-attached-property-in-silverlight/
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;
xmlns:xc="clr-namespace:FwWPFUIControls.Utility;assembly=FwWPFUIControls"
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;
http://lensbjerg.wordpress.com/2012/06/19/close-telerik-radwindow-from-viewmodel-with-attached-property-in-silverlight/
0
pavan
Top achievements
Rank 1
answered on 01 Aug 2014, 03:35 PM
Hi,
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?
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?