2009-07-22 13 views
1

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

答えて

1

ツールチップの高さと幅は、その内容に基づいています。だから、コンテンツをあなたが望むだけの大きさにする必要があります。

さらに詳しい説明のために、ツールチップを設定するコードを投稿する可能性がありますか?

+0

コードがあります。だから問題は、ツールチップの内側に画像が表示されているのですが、ツールチップと画像の間に隙間があり、画像がすべてツールチップ領域をカバーしたい場合です。 – Jake

+0

Oop、nvmが修正しました。御時間ありがとうございます。 – Jake

3

コードでは、ツールチップのheightプロパティとwidthプロパティをDouble.NaNに設定するだけで、幅と高さが動的に調整されます。

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

これはトリックを行います。

関連する問題