编译时出错

时间:2014-04-04 21:03:14

标签: c# wpf

我在下面的帖子中提出了更改后发现了新的错误。您可以找到有关错误的详细信息(请参见图1)。你知道我怎么解决这个问题吗?

How to declare a constructor?

http://i58.tinypic.com/qwwqvn.png

编辑: 对不起,我是新来的,所以我真的不知道情况如何。在上一篇文章中,有人建议我发一个新帖子,并附上该问题的链接。我现在将提供足够的细节,以便您了解正在发生的事情。

我有3个错误,我希望解决...

这些错误的代码发布在

下面

"参数1:无法转换为' object'到'字符串'"

"参数2:无法转换为System.Windows.Media.Brush'到'字符串'"

"' Microsoft.Samples.Kinect.ControlsBasics.SelectionDisplay.SelectionDisplay(string,string)'有一些无效的参数"

public SelectionDisplay(string itemId, string Tag)
    {
        this.InitializeComponent();

        this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);

    }


 var files = Directory.GetFiles(@".\GalleryImages");

            foreach (var file in files)
            {
                FileInfo fileInfo = new FileInfo(file);

                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = new Uri(file, UriKind.Relative);
                bi.EndInit();

                var button = new KinectTileButton
                {
                    Label = System.IO.Path.GetFileNameWithoutExtension(file),
                    Background = new ImageBrush(bi),
                    Tag = file
                };
                var selectionDisplay = new SelectionDisplay(button.Label as string, button.Tag as string);
                this.wrapPanel.Children.Add(button);
            }


  private void KinectTileButtonClick(object sender, RoutedEventArgs e)
    {

        var button = (KinectTileButton)e.Source;
        var image = button.CommandParameter as BitmapImage;
        var selectionDisplay = new SelectionDisplay(button.Label,button.Background); // aici poti apoi sa mai trimiti si imaginea ca parametru pentru constructor
        this.kinectRegionGrid.Children.Add(selectionDisplay);
        e.Handled = true;

    }

感谢您的理解,我希望这篇文章能够重新开放。

1 个答案:

答案 0 :(得分:0)

现在,您已经通过两种不同的方式调用了SelectionDisplay的构造函数:

var selectionDisplay = new SelectionDisplay(button.Label as string, button.Tag as string);
var selectionDisplay = new SelectionDisplay(button.Label,button.Background); // aici poti apoi sa mai trimiti si imaginea ca parametru pentru constructor

第一个是两个字符串,第二个是对象和画笔(因为你遇到的错误表示)。这意味着您需要两个构造函数:

public class SelectionDisplay
{
    public SelectionDisplay(string itemId, string Tag)
    {
        this.InitializeComponent();

        this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);

    }

    public SelectionDisplay(object label, Brush background)
    {
        //Do stuff
    }
}

现在,您可能只想考虑一个构造函数,但是您需要确保始终使用相同的参数类型调用它。

让我知道我是否可以澄清任何事情!

相关问题