如何将我创建的列表绑定到组合框? [英] How do I bind a list I create to a combobox?

查看:66
本文介绍了如何将我创建的列表绑定到组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我是 C#mvvm的新手,我想知道如何将我创建的列表绑定到我的comboBox。



< b>我尝试了什么:



VM

  public  Dictionary< TipContract,string> ComboTip 
{
get
{
return TipContract_dict ;
}

}

public 字典< Formatare,string> ComboFormatare
{
get { return Formatare_dict; }

}



// 提示合并枚举和字典以保存并显示在组合框中
public enum TipContract
{
C,N,D,T,M,L
}

public static readonly 字典< TipContract,string> TipContract_dict = new 字典< TipContract,string>()
{
{TipContract.C, Caracter},
{TipContract.N, 数字},
{TipContract.D, 数据 },
{TipContract.T, DataTime},
{TipContract.M, 备注},
{TipContract.L,< span class =code-string> 逻辑},

};


public enum Formatare
{
降低,上限,正确
}

公共 静态 readonly 字典< Formatare,string> Formatare_dict = new 字典< Formatare,string>(){
{Formatare.Lower, lower},
{Formatare.Upper, UPPER},
{Formatare.Proper, 正确 },

};

XML

 <   ComboBox       x:名称  =  cmbTip    

IsEnabled = True

< span class =code-attribute> < span class =code-attribute> SelectedValuePath =

< span class =code-attribute> DisplayMemberPath = 提示

< span class =code-attribute> SelectedValue = {Binding Formatare_dict}

解决方案

将我创建的列表绑定到我的comboBox mvvm - Google搜索 [ ^ ]

Hello! I'm new to C# mvvm and I would like to find out how do i bind a list i create to my comboBox.

What I have tried:

VM

public Dictionary<TipContract, string> ComboTip
        {
            get
            {
                return TipContract_dict;
            }

        }

        public Dictionary<Formatare, string> ComboFormatare
        {
            get { return Formatare_dict; }

        }



        //TipContract enum and dict to hold and display in combo boxes
        public enum TipContract
        {
            C, N, D, T, M, L
        }

        public static readonly Dictionary<TipContract, string> TipContract_dict = new Dictionary<TipContract, string>()
        {
            {TipContract.C, "Caracter"},
            {TipContract.N, "Numeric"},
            {TipContract.D, "Data"},
            {TipContract.T, "DataTime"},
            {TipContract.M, "Memo"},
            {TipContract.L, "Logic"},

        };
        
        
        public enum Formatare
        {
            Lower, Upper, Proper
        }

        public static readonly Dictionary<Formatare, string> Formatare_dict = new Dictionary<Formatare, string>(){
            {Formatare.Lower, "lower"},
            {Formatare.Upper, "UPPER"},
            {Formatare.Proper, "Proper"},
            
        };

XML

<ComboBox  x:Name="cmbTip" 

                               IsEnabled="True"

                               SelectedValuePath="Value" 

                               DisplayMemberPath="Tip"

                               SelectedValue="{Binding Formatare_dict}"

解决方案

bind a list i create to my comboBox mvvm - Google Search[^].


这篇关于如何将我创建的列表绑定到组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆