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

Set DialogResult from UserControl

3 Answers 200 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mike Hanson
Top achievements
Rank 1
Mike Hanson asked on 08 Aug 2008, 10:12 AM
I am using RadWindow to display property dialogs for entities in my application, these are created in code using an extension method of my application.

Is there a built in way for the content set for a RadWindow to detect the window in order to set the DialogResult and Close it?

Mike

3 Answers, 1 is accepted

Sort by
0
hwsoderlund
Top achievements
Rank 1
answered on 08 Aug 2008, 12:10 PM
I'm not sure about the DialogResult, but here's my code to close a window from within itself:

/// <summary> 
/// Recurses through the parent objects and looks for a RadWindow. If it is found, it is closed. 
/// </summary> 
public void CloseParentPopup(DependencyObject obj) 
    RadWindow win = CommonFunctions.GetParentOfSpecificType(obj, typeof(RadWindow)) as RadWindow; 
    if (win != null
        win.Close(); 

And you call it like this in any usercontrol:
CloseParentPopup(this as DependencyObject); 

0
hwsoderlund
Top achievements
Rank 1
answered on 08 Aug 2008, 12:12 PM
Sorry, forgot the helper function. This should be put in the static class CommonFunctions

/// <summary> 
/// This recurses the visual tree for a parent of a specific type 
/// </summary> 
/// <param name="parent"></param> 
/// <param name="targetType"></param> 
public static DependencyObject GetParentOfSpecificType(DependencyObject parent, Type targetType) 
    while (parent != null
    { 
        parent = VisualTreeHelper.GetParent(parent); 
        if (parent.GetType() == targetType || parent.GetType().BaseType == targetType) 
        { 
            return parent; 
        } 
    } 
 
    return null

0
Mike Hanson
Top achievements
Rank 1
answered on 08 Aug 2008, 12:19 PM
Thanks for those snippets, very helpful
Tags
Window
Asked by
Mike Hanson
Top achievements
Rank 1
Answers by
hwsoderlund
Top achievements
Rank 1
Mike Hanson
Top achievements
Rank 1
Share this question
or