WPF DataGrid.DataGridComboBoxColumn 数据绑定 可用自由示例

尝试了一些教程,不好使。手写一个比较自由的示例:

先上效果图:(不知道怎么多了一行,欢迎指教)

WPF DataGrid.DataGridComboBoxColumn 数据绑定 可用自由示例_第1张图片

xaml代码:


    
        
        
    
    
        
            
            
        
    

逻辑代码:

namespace DataBingTest
{
    /// 
    /// DB_DataGrid.xaml 的交互逻辑
    /// 
    public partial class DB_DataGrid : Window
    {
        public DB_DataGrid()
        {
            InitializeComponent();

            List infoList = new List();

            Info info02 = new Info();
            info02.sIdx = "1";
            infoList.Add(info02);
            info02 = new Info();
            info02.sIdx = "2";
            infoList.Add(info02);
            info02 = new Info();
            info02.sIdx = "3";
            infoList.Add(info02);

            DG1.DataContext = infoList;
        }
    }

    public class Info
    {
        public string sIdx { get; set; }
    }

    public class OSList
    {
        string[] txList = new string[] {"1" ,"2","3"};

        public string[] GetList()
        {
            return this.txList;
        }        
    }
}

 

参考:

1 微软教程:https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagridcomboboxcolumn?redirectedfrom=MSDN&view=netframework-4.7.2

2 https://blog.csdn.net/jiyanglin/article/details/83004460

 

 

你可能感兴趣的:(WPF,数据绑定,WPF)