This is a migrated thread and some comments may be shown as answers.
Get ListBox SelectedItem In RadWindow (all in code behind)
1 Answer 21 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jonathon asked on 27 Oct 2011, 12:27 AM

I have a RadWindow that is displayed when a user clicks a button. In that RadWindow I have a ListBox and a Button. I want the first item in the ListBox to be selected by default, and then when they click the button, I will get the value of the ListBox item. Here is a general layout of the code I have so far:

RadWindow userSelectionWindow = new RadWindow();
            StackPanel radWindowContent = new StackPanel();
            ListBox listBox = new ListBox();
            foreach (var server in Servers)
                ListBoxItem option = new ListBoxItem();
                option.Content = server.Name;
            Binding selected = new Binding();
            selected.Mode = BindingMode.OneTime;
            selected.Source = SelectedItem;
            listBox.SetBinding(Selector.SelectedItemProperty, selected);
            RadButton loginButton = new RadButton();
            loginButton.Command = new RelayCommand(CallMethod);
            loginButton.Content = "Log in";
            loginButton.Margin = new Thickness(0, 15, 0, 0);
            StyleManager.SetTheme(loginButton, new MetroTheme());
            userSelectionWindow.Content = radWindowContent;
            userSelectionWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            userSelectionWindow.CanMove = false;
            userSelectionWindow.ResizeMode = ResizeMode.NoResize;
            StyleManager.SetTheme(userSelectionWindow, new MetroTheme());

For some reason my string SelectedItem is never getting updated. Am my going about this the wrong way? What I need is the value of the SelectedItem in the ListBox after the user clicks the Log In button. I can do the functionality I need in XAML without the RadWindow, but doing all this in code behind is confusing.



1 Answer, 1 is accepted

Sort by
Telerik team
answered on 27 Oct 2011, 08:24 AM
Hello Jonathon,

I would suggest using the RadWindow control as a user control - please, refer to the following link - In this way, you could define the content in the xaml.

Hope this helps.

Kind regards,
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question