1

我在 wpf 中做一些事情,其中​​填充了数据网格。我需要数据网格中的每一行,当我指向鼠标时,应该可以看到一个包含图像的工具提示。这个图像对于数据网格的每一行都是不同的。我该怎么做。我已经能够做到这一点:

Image img = new Image();
        BitmapImage bmp = new BitmapImage();
        bmp.BeginInit();
        bmp.UriSource = new Uri(Directory.GetCurrentDirectory()+ "\\Kartik.JPG");
        bmp.DecodePixelHeight=200;
        bmp.DecodePixelWidth=200;
        bmp.EndInit();
        img.Source=bmp;
        ToolTipService.SetPlacement(dgAssortment, System.Windows.Controls.Primitives.PlacementMode.Center);
        ToolTipService.SetToolTip(dgAssortment, img);
        ToolTipService.SetShowDuration(dgAssortment, 99999999);

但这为整个数据网格显示了相同的图像,无论我将鼠标指针放在哪一行。如何使该图像对于数据网格中填充的每一行都不同。请帮忙。提前致谢。

4

1 回答 1

0

看起来您正在为整个数据网格设置工具提示:

ToolTipService.SetPlacement(dgAssortment,(我假设 dgAssortment 是您的数据网格)。

您需要对每一行执行此操作,方法是手动循环,或者挂钩到发生数据绑定时触发的某个事件。在 VS 2010 Beta 2 中,WPF DataGrid 有一个您可以使用的 LoadingRow 事件。

于 2009-11-27T18:46:35.203 回答