带有资源字典中标题的多项combobox?

我已按照此问题的接受答案来定义带有标题的多列combobox。

它对我不起作用,所以我对它进行了一些修改,现在它可以工作了。 这是用于创建带标题的多列combobox的xaml。

                                         

现在,我想在资源字典中定义之间的部分,这样我就不必再次编写它。 我还想在资源字典中添加两个function:

  1. 将Column-names和Column-values以某种方式绑定到某些东西(我不知道),以便任何两列combobox都可以使用此资源字典。

  2. 如果可能的话,我想在资源字典中添加一些逻辑,以便相同的资源字典可以用于具有任意数量列的任何combobox。

我认为有人可以引导我走向正确的方向,如果有人在过去做过这件事,那么我可能会得到一些帮助,这是提出这个问题的另一个意图。

如果我的上述问题仅使用xaml无法解决,那么我也很乐意接受解决方案。

试试这可能会对你有帮助。我刚刚编辑了combobox样式。请分开运行这段代码。

Xaml代码

                                             

你也可以在资源中编写这个combobox数据模板。所以你可以多次使用combobox datatempalate。我没有用资源写的。

                                 

c#代码

  InitializeComponent(); List cmb = new List(); cmb.Add(new ComboboxData("1.","Tidle", "~")); cmb.Add(new ComboboxData("2.", "Exclamation", "!")); cmb.Add(new ComboboxData("3.", "Ampersat", "@")); cmb.Add(new ComboboxData("4.","Ampersand", "&")); cmb.Add(new ComboboxData("5.","Dollar", "$")); Combobox.ItemsSource = cmb; Combobox1.ItemsSource = cmb; public class ComboboxData { public string index { get; set; } public string name { get; set; } public string symbol { get; set; } public ComboboxData(string index,string name,string symbol) { this.index = index; this.name = name; this.symbol = symbol; } } 

同样,您也可以编辑4列,5列的模板。

产量

在此处输入图像描述