WPF,Access组合框选择项

编程入门 行业动态 更新时间:2024-10-26 04:21:40
本文介绍了WPF,Access组合框选择项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个组合框,有四个静态可能的选项,如下所示

I have a combobox that has four static possible selections, shown below

MainWindow.xaml

<Grid> <ComboBox Name="combobox" IsEditable="True" SelectionChanged="ComboBox_SelectionChanged" Text="Default Text" <ComboBoxItem Name="ComboBoxItem1">1</ComboBoxItem> <ComboBoxItem Name="ComboBoxItem2">2</ComboBoxItem> <ComboBoxItem Name="ComboBoxItem3">3</ComboBoxItem> <ComboBoxItem Name="ComboBoxItem4">4</ComboBoxItem> </ComboBox> <StackPanel Name="dock"> </StackPanel> </Grid>

我为使用此方法选择的每个组合框项目创建一个扩展器。

I'm creating an expander for each combobox item that is selected using this method.

MainWindow.xaml.cs

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var itemIndex = combobox.SelectedItem; Expander expander = new Expander { Header = thisbobox.Name }; dock.Children.Add(expander); }

我知道我可以访问combobox名称,但我不知道访问comboboxitem名称。我已尝试使用

I know I can access the combobox name, but I'm not sure how to access the comboboxitem name. I've tried using

Header = thisbobox.ComboBoxItem.Name

和其他变种,但我没有成功。我只是试图使每个扩展器的头到comboboxitem的名称。

And other variants of that, but I've had no success. I'm just trying to make the header of each expander into the name of the comboboxitem. Any help is appreciated.

推荐答案

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var itemIndex = combobox.Text; string name = (combobox.SelectedItem as ComboBoxItem).Name; var obj = dock.FindName("Exp_Name"); if (obj == null) { Expander expander = new Expander(); expander.Header = name; expander.Name = "Exp_Name"; dock.Children.Add(expander); this.RegisterName(expander.Name, expander); } else { var element = obj as Expander; element.Header = name; } }

希望这有帮助。

更多推荐

WPF,Access组合框选择项

本文发布于:2023-07-19 07:17:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   WPF   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!