Ich habe meinen Code sowohl XAML und C#, aber es funktioniert nicht. Bitte beraten. Dankwie 2 Combox miteinander interagieren RSS
enter code here
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="4*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.7*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="0.7*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Select Country" Grid.Row="0" Grid.Column="0"></TextBlock>
<ComboBox x:Name="CmbxCountry" SelectionChanged="CmbxCountry_SelectionChanged" Grid.Row="0" Grid.Column="1"></ComboBox>
<TextBlock Text="Select State" Grid.Row="2" Grid.Column="0"></TextBlock>
<ComboBox x:Name="CmbxState" Grid.Row="2" Grid.Column="1"></ComboBox>
</Grid>
Namespace Survey_Model { public partial class Mainpage: Usercontrol { // Private Pinsel _selectedBrush = new SolidColorBrush (Color.FromArgb (255, 255, 0, 0)); // private Brush _normalBrush = neuer SolidColorBrush (Color.FromArgb (255, 0, 0, 0));
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
List<Country> list = new List<Country>
{
new Country{ Name = "USA" },
new Country{ Name = "China"},
new Country{States = GetStates()}
};
CmbxCountry.ItemsSource = list;
CmbxCountry.DisplayMemberPath = "Name";
}
private List<State> GetStates()
{
List<State> list = new List<State>
{
new State{ Name = "NJ" },
new State{ Name = "NY" },
new State{ Name = "NV" },
new State{ Name = "CT" },
new State{ Name = "CA" }
};
return list;
}
private void CmbxCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var cmbx = sender as ComboBox;
var selectedItem = cmbx.SelectedItem as Country;
CmbxState.ItemsSource = selectedItem.States;
CmbxState.DisplayMemberPath = "Name";
}
}
public class Country
{
public string Name { get; set; }
public List<State> States { get; set; }
}
public class State
{
public string Name { get; set; }
}
}
Vielen Dank. – user352385
Gern geschehen. :) –