Set DialogResult from UserControl

4 posts, 0 answers
  1. Mike Hanson
    Mike Hanson avatar
    25 posts
    Member since:
    Jul 2005

    Posted 08 Aug 2008 Link to this post

    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
  2. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 08 Aug 2008 Link to this post

    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); 

  3. DevCraft banner
  4. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 08 Aug 2008 Link to this post

    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

  5. Mike Hanson
    Mike Hanson avatar
    25 posts
    Member since:
    Jul 2005

    Posted 08 Aug 2008 Link to this post

    Thanks for those snippets, very helpful
Back to Top