【发布时间】:2017-05-11 20:32:19
【问题描述】:
我编写了一个在画布中绘制元素的应用程序,如 this other post
我按照@grek40 的指示做了,效果很好。
现在我想为画布中绘制的元素添加一个工具提示(仅限由 Border 类表示的 Tasks 元素)。这是我的代码:
<DataTemplate DataType="{x:Type local:TaskItem}">
<Border
Background="#0074D9"
BorderBrush="#001F3F"
BorderThickness="2"
Width="{Binding Width}"
Height="{Binding Height}">
<TextBlock
Text="{Binding Id}"
FontSize="20"
Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Border.ToolTip>
<ToolTip Background="#D5F0F0FF">
<StackPanel>
<TextBlock Text="Reading Suggestion" FontWeight="Bold"/>
<TextBlock Text="Charles Dickens" Margin="5"/>
</StackPanel>
</ToolTip>
</Border.ToolTip>
</Border>
</DataTemplate>
但它不起作用。当我悬停任务元素(边框项目)时,什么也没有发生。有什么想法吗?
更新
网格 (x:Name="grid1") 包含在处理缩放和填充的自定义控件中。我在this post in codeplex 之后实现了这个(我遵循了“简单示例代码”)。
所以我的 xaml 看起来像这样:
<ScrollViewer
x:Name="scroller"
CanContentScroll="True"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible"
>
<!--
This is the control that handles zooming and panning.
-->
<ZoomAndPan:ZoomAndPanControl
x:Name="zoomAndPanControl"
Background="LightGray"
MouseDown="zoomAndPanControl_MouseDown"
MouseUp="zoomAndPanControl_MouseUp"
MouseMove="zoomAndPanControl_MouseMove"
MouseWheel="zoomAndPanControl_MouseWheel"
>
<!--
This Canvas is the content that is displayed by the ZoomAndPanControl.
Width and Height determine the size of the content.
-->
<Grid x:Name="grid1">
<ItemsControl x:Name="content"
ItemsSource="{Binding TaskItems}"
ItemContainerStyle="{StaticResource canvasTaskItemStyle}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas
Background="White"
Height="2000"
Width="2000"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ItemsControl x:Name="contentLines"
ItemsSource="{Binding TaskLineItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas
Background="Transparent"
Height="2000"
Width="2000"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</ZoomAndPan:ZoomAndPanControl>
</ScrollViewer>
ZoomAndPanControl 的命令是否会干扰工具提示?
【问题讨论】:
-
你确定吗?我刚刚将工具提示合并到我的示例中,它显示没有问题。也许您项目的其他部分受到干扰?
-
这是可能的,因为我将您的代码放在处理缩放和平移的自定义控件中。我已经用有关它的信息更新了帖子。谢谢