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;
}