This question is locked. New answers and comments are not allowed.
Hi,
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:
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.
Thanks,
Jonathon
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; listBox.Items.Add(option); } Binding selected = new Binding(); selected.Mode = BindingMode.OneTime; selected.Source = SelectedItem; listBox.SetBinding(Selector.SelectedItemProperty, selected); radWindowContent.Children.Add(listBox); 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()); radWindowContent.Children.Add(loginButton); userSelectionWindow.Content = radWindowContent; userSelectionWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; userSelectionWindow.CanMove = false; userSelectionWindow.ResizeMode = ResizeMode.NoResize; StyleManager.SetTheme(userSelectionWindow, new MetroTheme()); userSelectionWindow.Show();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.
Thanks,
Jonathon