码迷,mamicode.com
首页 > 其他好文 > 详细

WPF combobox

时间:2014-06-09 18:45:56      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

先写一个数据类Grade.cs

bubuko.com,布布扣
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" });
        }
    }
}
bubuko.com,布布扣

在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

WPF combobox

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/ZXdeveloper/p/3777363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!