0

如何以编程方式在 WPF 中将位图图像添加为组合框项?

我正在ComboBox动态创建:

private ComboBox CreateSymbolComboBox(List<BitmapImage> images, int selectedIndex, bool isEnabled)
    {
        ComboBox cb = new ComboBox();

        foreach (BitmapImage img in images)
        {

            cb.Items.Add();
        }

        return cb;
    }
4

1 回答 1

0

BitmapImage实际上源自ImageSource. 因此,您可以将其用作Sourceof Image。观察:

private ComboBox CreateSymbolComboBox(List<BitmapImage> images, int selectedIndex, bool isEnabled)
{
    ComboBox cb = new ComboBox();

    foreach (BitmapImage img in images)
    {

        cb.Items.Add(new Image() {Source = img});
    }

    return cb;
}
于 2013-07-23T06:21:32.690 回答