C# 在WinRT中移动工具提示
在WinRT(Windows应用商店应用程序)中,我创建了一个工具提示,并将其设置为如下元素:C# 在WinRT中移动工具提示,c#,.net,windows-store-apps,winrt-xaml,C#,.net,Windows Store Apps,Winrt Xaml,在WinRT(Windows应用商店应用程序)中,我创建了一个工具提示,并将其设置为如下元素: dragTip = new ToolTip(); dragTip.Content = "Test"; ToolTipService.SetToolTip(element as DependencyObject, dragTip); dragTip.IsOpen = true; 我想在鼠标移动时移动此工具提示。有办法吗
dragTip = new ToolTip();
dragTip.Content = "Test";
ToolTipService.SetToolTip(element as DependencyObject, dragTip);
dragTip.IsOpen = true;
我想在鼠标移动时移动此工具提示。有办法吗?还是另一种选择?我想在用户拖动元素时向他/她显示一个提示
更新
以下是我根据@Sajeetharan的建议采取的方法:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" PointerMoved="homeGrid_PointerMoved" x:Name="homeGrid">
....
<GridView x:Name="content" CanDragItems="True" DragItemsStarting="content_DragItemsStarting">
...
</GridView>
<Popup Name="DeepZoomToolTip">
<Border CornerRadius="1" Padding="1" IsHitTestVisible="False">
<TextBlock Text="Here is a tool tip" />
</Border>
</Popup>
....
</Grid>
private void content_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
DeepZoomToolTip.IsOpen = true;
}
private void homeGrid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var position = e.GetCurrentPoint(homeGrid).Position;
DeepZoomToolTip.HorizontalOffset = position.X;
DeepZoomToolTip.VerticalOffset = position.Y;
}
....
...
....
私有void内容\u DragItemsStarting(对象发送方,DragItemsStartingEventArgs e)
{
DeepZoomToolTip.IsOpen=true;
}
私有void homeGrid_PointerMoved(对象发送方,PointerRoutedEventArgs e)
{
var位置=e.GetCurrentPoint(homeGrid).position;
DeepZoomToolTip.HorizontalOffset=位置.X;
DeepZoomToolTip.VerticalOffset=位置.Y;
}
请注意,工具提示将移动,但在拖动项目时不会移动。您可以使用弹出控件执行此操作,以下是完整的线程
XAML:
私有无效图像\u MouseMove(对象发送器,MouseEventArgs e)
{
DeepZoomToolTip.IsOpen=true;
DeepZoomToolTip.HorizontalOffset=e.GetPosition(LayoutRoot).X;
DeepZoomToolTip.VerticalOffset=e.GetPosition(LayoutRoot).Y;
}
专用void Image_MouseLeave(对象发送器,MouseEventArgs e)
{
DeepZoomToolTip.IsOpen=false;
}
你是什么意思?鼠标光标在其所连接的控件上之后的工具提示?嗯,正常情况下应该可以工作,但由于某些原因,当我尝试此操作时,弹出窗口
仅在指针未按下时移动(网格未处于拖动模式)。我尝试将事件添加到主网格中,但它似乎不起作用,这很奇怪。@AlirezaNoori您可以发布工具提示中的事件吗?
<Canvas x:Name="LayoutRoot" Background="White">
<Image Source="/sam.png" MouseMove="Image_MouseMove" MouseLeave="Image_MouseLeave"/>
<Popup Name="DeepZoomToolTip">
<Border CornerRadius="1" Padding="1" IsHitTestVisible="False">
<TextBlock Text="Here is a tool tip" />
</Border>
</Popup>
</Canvas>
private void Image_MouseMove(object sender, MouseEventArgs e)
{
DeepZoomToolTip.IsOpen = true;
DeepZoomToolTip.HorizontalOffset = e.GetPosition(LayoutRoot).X;
DeepZoomToolTip.VerticalOffset = e.GetPosition(LayoutRoot).Y;
}
private void Image_MouseLeave(object sender, MouseEventArgs e)
{
DeepZoomToolTip.IsOpen = false;
}