zoukankan      html  css  js  c++  java
  • 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();
  • 相关阅读:
    SQL Server 动态行转列(参数化表名、分组列、行转列字段、字段值)
    Web Api 跨域解决方案
    Web Api Session开启会话支持
    Web Service 学习
    省市选择器
    如何创建圆形头像和圆角图片
    E
    二叉树
    素数筛法
    Color Me Less
  • 原文地址:https://www.cnblogs.com/ZXdeveloper/p/3777363.html
Copyright © 2011-2022 走看看