WPF ComboBox & Text

索引サイト

多少「手抜き」のような気もするが、・・使い易ければ、まあ、それはそれで




<ComboBox Margin="5" Name="comboBox2" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" />
<ComboBox Margin="5" Name="comboBox1" IsTextSearchCaseSensitive="False" SelectionChanged="comboBox1_SelectionChanged" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" />
<TextBox Margin="7,7,40,7" Name="textBox1" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2"
Text="{Binding ElementName=comboBox1,Path=Text}" />
<TextBlock Margin="5" Name="textBlock1" Text="TextBlock" Background="Cyan" Grid.Column="1" Grid.Row="6" />
<Button Margin="5" Name="button1" Click="button1_Click" Grid.Column="2" Grid.Row="6" Content="AddItem" />




int z_selectedIndex;
private void button1_Click(object sender, RoutedEventArgs e)
{
comboBox1.Items.Add("111111111");
comboBox1.Items.Add("222222222");
comboBox1.Items.Add("333333333");
comboBox1.Items.Add("444444444");
comboBox1.Items.Add("555555555");
}
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
z_selectedIndex = comboBox1.SelectedIndex;
textBlock1.Text = "index:" + z_selectedIndex;
}



AX