如何使构造函数显示所选图像

本文关键字:图像 显示 何使 构造函数 | 更新日期: 2023-09-27 17:56:54

我应该在这个构造函数中写什么才能显示从上一个列表中选择的图像。

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

例如,如果我从图像列表中选择考拉(见图1),应该会打开一个新窗口,其中包含考拉的宽图像和简短描述。我试图尽可能清楚;我还发布了生成图像的代码。

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

http://i57.tinypic.com/2liegrk.png

如何使构造函数显示所选图像

你能改写一下你的要求吗?我得到的是,您有一些图像的列表,可能还有一些描述,一旦您单击其中一张图像,它就会在新屏幕上大开大合。您希望通过视图模型的构造函数执行此功能。请确认这是否是正确的理解。