0
我有一個Canvas
,我在其上繪製了多個Rectangles
,它們代表畫布上多個用戶選擇的位置。顯示一組矩形的自定義工具提示(圖形上的點)
我想爲每個矩形創建一個ToolTip
,該矩形顯示矩形的x和y座標以及到另一個點的距離:「手寫筆點」。
當創建矩形時,x和y座標是已知的,但與觸筆點的距離不是,因此工具提示每次顯示時都需要更新其文本。
我試過使用下面的綁定,但這只是在工具提示中放置文本「System.Windows.Control.ToolTip」。
...
Rectangle rectangle = new Rectangle
{
Width = _rectWidth,
Height = _rectWidth,
Fill = new SolidColorBrush(Colors.Red)
};
rectangle.ToolTip = new ToolTip();
Binding binding = new Binding()
{
Source = this,
Path = new PropertyPath("ToolTipBinding"),
Mode = BindingMode.OneWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(rectangle.ToolTip as ToolTip ,ToolTipService.ToolTipProperty, binding);
}
public string ToolTipBinding
{
get
{
return "How would i get the data context here (even if it bound correctly)";
}
}
任何幫助非常感謝。
'我有一個Canvas,我在其上畫了一些Rectangles' - 刪除所有這些,並使用適當的DataBinding和ItemsControl。 – 2014-12-03 12:11:29
@HighCore謝謝,我認爲我有一個與ItemsControl工作解決方案現在將添加答案。 – 2014-12-04 08:54:18