RadWindow OnOpened method

12 posts, 0 answers
  1. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 14 Jul 2011 Link to this post

    Looks like with the new release, this was deprecated on the RadWindow class, which we’re overriding:

     

                [Obsolete("The Opened event will not be fired anymore.")]

                protected virtual void OnOpened(RoutedEventArgs args);

     

    There’s no indication what the replacement might be.  Can you tell me what replaces this method.?
      

    Thanks,
    Amit

  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 18 Jul 2011 Link to this post

    Hello Amit,

    You don't need the event anymore, just write the code you want to be executed after the Show() method.

    Please let us know if you need further information.

    Greetings,
    Konstantina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Terry Foster
    Terry Foster avatar
    60 posts
    Member since:
    Sep 2009

    Posted 18 Jul 2011 Link to this post

    Well, we were deriving from RadWindow to provide some common functionality among all our windows, like this:

    protected override void OnOpened(RoutedEventArgs args)

     

    {

     

     

        if (Header is string)

     

        {

            Header =

     

    new TextBlock()

     

            {

                FontWeight =

     

    FontWeights.Bold,

     

                Margin =

     

    new Thickness(4, 0, 4, 0),

     

                Text = (

     

    string)Header,

     

            };

        }

     

     

        base.OnOpened(args);

     

    }


    Nothing like this is possible anymore?

    Terry
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 19 Jul 2011 Link to this post

    Hello Terry,

    You can override the Show() method and do your work there.

    Please let us know if you experience any difficulties.

    Kind regards,
    Konstantina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  5. Terry Foster
    Terry Foster avatar
    60 posts
    Member since:
    Sep 2009

    Posted 19 Jul 2011 Link to this post

    Unless I'm completely missing something, the 'Show' method is not virtual (version 2011.2.712.1040).

    Terry
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 21 Jul 2011 Link to this post

    Hello Terry,

    Sorry for misleading you. We are currently making some improvements to the RadWindow. So, the method which you will be able to override is called ShowWindow() and you will be able to use it with the next internal build.
    Hope this is acceptable time frame for you.

    All the best,
    Konstantina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  7. Terry Foster
    Terry Foster avatar
    60 posts
    Member since:
    Sep 2009

    Posted 23 Sep 2011 Link to this post

    Hi again,

    Is the overrideable 'ShowWindow' method available in the new release (9/21/11)?  I'm not seeing any mention in the release notes.

    Thanks,
    Terry
  8. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 27 Sep 2011 Link to this post

    Hi Terry,

    Nothing is changed about this method - it is still available. Please find attached a sample project in which this is illustrated.

    Best wishes,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  9. Nandita
    Nandita avatar
    9 posts
    Member since:
    Mar 2011

    Posted 04 Nov 2011 Link to this post

    Hi,

    That is ok to override the ShowWindow method but i wanted to achieve something else. What i have is a common method to open RadWindow and in that method i want to set the DataContext of UserControl to the DataContext of the RadWindow as explained in the code below:

    /// <summary>
            /// Method to open the modal window using screen instance in it
            /// </summary>
            /// <typeparam name="T">Generic User Control</typeparam>
            /// <param name="userControl">User Control Instance</param>
            /// <param name="controlHeader">screen header title</param>
            public static void ShowUserControlTelerikWindow<T>(T userControl,
                                                string controlHeader) where T: UserControl
            {
                //Define the Dialogue Parameter of Message window
                //RadWindow window = new RadWindow();
                window.ResizeMode = ResizeMode.NoResize;
                window.Content = userControl;
                window.Header = controlHeader;
                 
                window.DataContext = userControl.DataContext;
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                // The next event is depricated, so it's not called.
                window.Opened+= (sender, e) =>
                                       {
                                           ((RadWindow) sender).DataContext = userControl.DataContext;
                                       };
                // The next event worked but there were some other issues which are irrelevant so this will not help.
                window.Activated+= (sender, e) =>
                                       {
                                           ((RadWindow) sender).DataContext = userControl.DataContext;
                                       };
                window.ShowDialog();
               // If i try to set DataContext here after show as you suggested then at this point of time the DataContext o userControl is null.
                 ((RadWindow) sender).DataContext = window.DataContext;
            }

    Please suggest a way for this.
  10. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 08 Nov 2011 Link to this post

    Hello Nandita,

    Could you please try the following:

    window.SetBinding(DataContextProperty, new Binding("DataContext") { Source = this });

    Initially, you don't need to hook to the Opened event to set the DataContext.

    Let us know if that resolved the issue.

    All the best,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  11. Nandita
    Nandita avatar
    9 posts
    Member since:
    Mar 2011

    Posted 10 Nov 2011 Link to this post

    I have tried the following:

    window.SetBinding(RadWindow.DataContextProperty, new Binding("DataContext") { Source = userControl.DataContext });

    But with negative results. After using this even after showdialog(), the data context is null.

    I already have a workaround but that is stupid, this is what i am doing.

    /// <summary>
            /// Method to open the modal window using screen instance in it
            /// </summary>
            /// <typeparam name="T">Generic User Control</typeparam>
            /// <param name="userControl">User Control Instance</param>
            /// <param name="controlHeader">screen header title</param>
            public static void ShowUserControlTelerikWindow<T>(T userControl)  where T: UserControl
            {
                window.ResizeMode = ResizeMode.NoResize;
                window.Content = userControl;
                window.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen;
                var setRadWindowDataContextTimer = new DispatcherTimer();
                setRadWindowDataContextTimer.Tick += (s, e) =>
                                                   {
                                                       window.DataContext = userControl.DataContext;
                                                       setRadWindowDataContextTimer.Stop();
                                                   };
                setRadWindowDataContextTimer.Interval = TimeSpan.FromMilliseconds(300);
                setRadWindowDataContextTimer.Start();
                window.ShowDialog();
            }

    Using the timer. This helps but i don;t require this.

    Please suggest something else.
  12. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 14 Nov 2011 Link to this post

    Hello Nandita,

    You need to set the DataContext of the window to be equal to the UserControl itself, not to the DataContext of the UserControl, as mentioned in my previous post.

    Kind regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top