Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 与';System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement)和#x27;有一些无效的参数_C#_.net_Wpf - Fatal编程技术网

C# 与';System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement)和#x27;有一些无效的参数

C# 与';System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement)和#x27;有一些无效的参数,c#,.net,wpf,C#,.net,Wpf,我正在尝试将此方法添加到网格中,并将其放置在网格中的单元格中。我猜我得到的错误是因为我无法将:private void BarCode()转换为System.Windows.Controls.UIElementCollection我该如何解决这个问题 myGrid.Children.Add(BarCode()); 您的BarCode()方法需要返回UIElement您可以这样编写BarCode函数 private UIElement BarCode() { Image myBarCod

我正在尝试将此方法添加到网格中,并将其放置在网格中的单元格中。我猜我得到的错误是因为我无法将:
private void BarCode()
转换为
System.Windows.Controls.UIElementCollection
我该如何解决这个问题

myGrid.Children.Add(BarCode());

您的
BarCode()
方法需要返回
UIElement

您可以这样编写
BarCode
函数

private UIElement BarCode()
{
    Image myBarCode = new Image();
    myBarCode.Source = new BitmapImage(new Uri("bitmap.png", UriKind.RelativeOrAbsolute));
    return myBarCode;
}