XAMLとC#の両方のコードを添付しましたが、動作しません。お知らせ下さい。おかげ2 comboxを互いにやりとりさせる方法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>
名前空間Survey_Model { 公共部分クラスメインページ:ユーザーコントロール {// プライベートブラシ_selectedBrush =新しいSolidColorBrushの(Color.FromArgb(255、255、0、 0)); //プライベートブラシ_normalBrush =新しい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; }
}
}
ありがとうございました。 – user352385
ようこそ。 :) –