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

RadWindow OnOpened method

11 Answers 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 14 Jul 2011, 03:05 PM

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

11 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 18 Jul 2011, 12:18 PM
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!

0
Terry Foster
Top achievements
Rank 1
answered on 18 Jul 2011, 02:20 PM
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
0
Konstantina
Telerik team
answered on 19 Jul 2011, 03:50 PM
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!

0
Terry Foster
Top achievements
Rank 1
answered on 19 Jul 2011, 04:05 PM
Unless I'm completely missing something, the 'Show' method is not virtual (version 2011.2.712.1040).

Terry
0
Konstantina
Telerik team
answered on 21 Jul 2011, 03:38 PM
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!

0
Terry Foster
Top achievements
Rank 1
answered on 23 Sep 2011, 12:55 PM
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
0
Konstantina
Telerik team
answered on 27 Sep 2011, 12:58 PM
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 >>
0
Nandita
Top achievements
Rank 1
answered on 04 Nov 2011, 09:39 AM
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.
0
Konstantina
Telerik team
answered on 08 Nov 2011, 09:04 AM
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 >>
0
Nandita
Top achievements
Rank 1
answered on 10 Nov 2011, 10:34 AM
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.
0
Konstantina
Telerik team
answered on 14 Nov 2011, 05:41 PM
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 >>
Tags
General Discussions
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Terry Foster
Top achievements
Rank 1
Nandita
Top achievements
Rank 1
Share this question
or