gpt4 book ai didi

c# - 动态设置工具提示宽度和高度

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:35 25 4
gpt4 key购买 nike

在 WPF (C#) 中有一种方法可以动态设置工具提示的高度和宽度(意思是在代码中)。感谢您的帮助。

System.Windows.Controls.Image td = new System.Windows.Controls.Image();

BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(Directory.GetCurrentDirectory() + "/Homepage.jpg");
td.Width = 530;
td.Height = 392;
//myBitmapImage.DecodePixelWidth = 430;
//myBitmapImage.DecodePixelHeight = 292;
myBitmapImage.EndInit();
td.Source = myBitmapImage;

TextBlock textBlock = new TextBlock();
BrushConverter conv = new BrushConverter();
string strColor1 = bannerColor.SelectedItem.ToString();
strColor1 = strColor1.Substring(strColor1.IndexOf(' ') + 1);
SolidColorBrush col = conv.ConvertFromString(strColor1) as SolidColorBrush;

textBlock.Foreground = col;
textBlock.FontWeight = FontWeights.Bold;
textBlock.FontSize = 18;
textBlock.FontFamily = new System.Windows.Media.FontFamily("Tahoma");
textBlock.Width = 100;
textBlock.Height = 20;
textBlock.Text = "BACKUP";
textBlock.Margin = new Thickness(5, 5, 425, 367);

Grid toolTipPanel = new Grid();
toolTipPanel.Width = 530;
toolTipPanel.Height = 392;
toolTipPanel.Children.Add(td);
toolTipPanel.Children.Add(textBlock);

ToolTipService.SetToolTip(image1, toolTipPanel);
ToolTipService.SetShowDuration(image1, 999999999);`

最佳答案

在您的代码中,只需将工具提示的高度和宽度属性设置为 Double.NaN 即可动态调整宽度和高度。

_toolTip.Width = Double.NaN;
_toolTip.Height = Double.NaN;

这样就可以了。

关于c# - 动态设置工具提示宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1168646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com