WPF combobox

先写一个数据类Grade.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace ImgProWPF
{
public class Grade
{
public string Name { set; get; }
}
public class GradeAdd:ObservableCollection<Grade>
{
public GradeAdd()
{
this.Add(new Grade { Name = "0" });
this.Add(new Grade { Name = "0.5" });
this.Add(new Grade { Name = "1" });
this.Add(new Grade { Name = "2" });
this.Add(new Grade { Name = "3" });
this.Add(new Grade { Name = "4" });
this.Add(new Grade { Name = "5" });
}
}
}

在MainWindow.xaml里调用

xmlns:local="clr-namespace:ImgProWPF"

 <Grid.Resources>
<local:GradeAdd x:Key="grade"/>
</Grid.Resources>

<ComboBox x:Name="comPersonalGrade" Grid.Column="1" Grid.Row="12" SelectedItem="0" ItemsSource="{StaticResource grade}" DisplayMemberPath="Name"/>

以上为绑定里数据,可以看到内容

下面为获得选中的内容

            Grade gradeP = (Grade)comPersonalGrade.SelectedItem;
string gradep = gradeP.Name.ToString();

WPF combobox,布布扣,bubuko.com

时间: 2024-08-06 07:59:04

WPF combobox的相关文章

WPF ComboBox Binding Enum

什么都不说,先看代码 枚举: namespace WpfAppTest { public enum Week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } } 页面: <Window x:Class="WpfAppTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

wpf ComboBox 样式修改

<Window x:Class="ComboBoxStyle.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width=

WPF ComboBox Binding

public ConnectionViewModel { private readonly CollectionView _phonebookEntries; private string _phonebookeEntry; public CollectionView PhonebookEntries { get { return _phonebookEntries; } } public string PhonebookEntry { get { return _phonebookEntry;

WPF{ComboBox绑定类对象, 下拉列显示的值,与取到的值}

DisplayMemberPath 是用来显示下拉列表的值 SelectedValuePath是用来取得选中项的值. ComboBox绑定类对象, 下拉列显示的值,与取到的值 string. Join的作用 输出结果是

WPF ComboBox下拉绑定Treeview 功能的实现

因为项目需要,接触到这个功能点,借助网络还有自己的一点摸索,实现了这个功能.相关代码如下: XAML部分的代码: <ComboBox Grid.Row="0" Grid.Column="9" HorizontalAlignment="Left" Name="OrgaComboBox" Margin="6" VerticalAlignment="Top" Width="20

WPF Combobox数据绑定Binding

combobox数据绑定List链表集合区分显示值与选择的值 整体效果: 根据combobox选择情况分别打印选取值与显示值 代码: Windows窗体: 1 <Window x:Class="ComboxBinding.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.

WPF ComboBox样式

一.样式的样子就是这样的 二.样式Style - 不可编辑请设置 属性为ReadOnly=true属性 1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 3 <!--下拉按钮--> 4 <Style

编写 WPF DataGrid 列模板,实现更好的用户体验

Julie Lerman 下载代码示例 最近我在为一个客户做一些 Windows Presentation Foundation (WPF) 方面的工作. 虽然我提倡使用第三方工具,但有时也会避免使用这些工具,这样做是为了体验那些坚持使用 Visual Studio 安装附带工具的开发人员会面临什么样的难题. 祝我好运吧!我们来研究一下 WPF DataGrid. 即便有 Web 搜索的帮助和来自在线论坛的建议,仍然有一些用户体验问题花了我几天时间才解决. 将 DataGrid 列分解为成对的互

WPF的ComboBox 数据模板自定义

WPF的ComboBox 有些时候不能满足用户需求,需要对数据内容和样式进行自定义,下面就简要介绍一下用数据模板(DataTemplate)的方式对ComboBox 内容进行定制: 原型设计如下: 步骤: 1.新建一个WPF应用程序WpfAppDemo(VS2012),并新建一个images文件夹(上传图片素材); 2.在主界面MainWindow.xaml文件中添加一个Label.ComboBox 和Button控件,如下图: 代码如下: 1 <Window x:Class="WpfAp