2012-04-07 108 views
4

長話短說:我有一個窗口,在ListBox中顯示一堆圖表。當mouseOver圖表(使用LineSeries)時,會有一行跟隨dataPoints(捕捉到dataPoint位置)。在該行附近,我展示了一個由彈出窗口提供的工具提示,該窗口顯示有關這些數據點的信息。WPF「工具提示」彈出窗口閃爍

"tooltip" as it appears

到目前爲止這麼好。問題是當我嘗試將鼠標移動到工具提示上時,彈出窗口開始閃爍(就像它在打開/關閉循環中一樣)。我已經設置了彈出窗口和兒童IsHitTestVisible="False"

作爲一個臨時的解決方案在彈出的「雲」出來的遊標方式喜歡這裏:

"tooltip" repositioned

...但幾乎沒有「可以理解的」。

現在出現了這樣一個問題:怎麼了?爲什麼鼠標懸停時彈出菜單開始閃爍。

歡迎任何反饋意見

PS。工具提示XAML(它是在代碼中創建的,但是在這裏):

圖表的datacontext是綁定到類的數據,也有一些圖表的事件是通過命令實現的。彈出窗口是在類的構造函數創建,

ppchart = New Popup() With {.AllowsTransparency = True, .IsHitTestVisible = False,.StaysOpen = True} 

...在MouseMoveCommand彈出的孩子創建:

Dim ppCont As XElement = <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" IsHitTestVisible="False" VerticalAlignment="Top"> 
            <Grid.RowDefinitions> 
             <RowDefinition Height="Auto"/> 
             <RowDefinition Height="Auto"/> 
            </Grid.RowDefinitions> 
            <Rectangle Opacity="0.5" Grid.RowSpan="2" IsHitTestVisible="False" StrokeThickness="0" RadiusX="2" RadiusY="2" Fill="#FFBABABA"/> 
            <TextBlock Text="{Binding Over, StringFormat=HH:mm}" FontSize="9" TextAlignment="Center" FontFamily="Segoe UI" IsHitTestVisible="False" Margin="1"/> 
            <ListBox x:Name="listBox" ItemsSource="{Binding Points}" Background="{x:Null}" BorderBrush="{x:Null}" FontSize="8" Margin="1,0,1,1" Grid.Row="1" IsHitTestVisible="False" IsTextSearchEnabled="False" HorizontalAlignment="Stretch"> 
             <ListBox.ItemContainerStyle> 
              <Style TargetType="{x:Type ListBoxItem}"> 
               <Setter Property="Background" Value="Transparent"/> 
               <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
               <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
               <Setter Property="Padding" Value="0"/> 
               <Setter Property="IsHitTestVisible" Value="False"/> 
              </Style> 
             </ListBox.ItemContainerStyle> 
             <ListBox.ItemTemplate> 
              <DataTemplate> 
               <Grid IsHitTestVisible="False"> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition Width="Auto"/> 
                 <ColumnDefinition Width="Auto"/> 
                 <ColumnDefinition Width="Auto"/> 
                </Grid.ColumnDefinitions> 
                <Rectangle Fill="{Binding Culoare}" Width="3" HorizontalAlignment="Left" Margin="1" IsHitTestVisible="False"/> 
                <TextBlock Text="{Binding Operation}" HorizontalAlignment="Stretch" IsHitTestVisible="False" Grid.ColumnSpan="1" Grid.Column="1"/> 
                <TextBlock Text="{Binding points.Value}" HorizontalAlignment="Stretch" Grid.Column="2" TextAlignment="Right" IsHitTestVisible="False"/> 
               </Grid> 
              </DataTemplate> 
             </ListBox.ItemTemplate> 
            </ListBox> 
           </Grid> 

     ppchart.Effect = New Effects.DropShadowEffect() With {.Opacity = 0.5, .BlurRadius = 5, .Direction = 80, .Color = Colors.Black} 
     ppchart.Child = CType(XamlReader.Load(New XmlTextReader(New StringReader(ppCont.ToString))), UIElement) 

重新編輯:這是怎麼看起來像

enter image description here

+0

可以發佈用於工具提示的XAML嗎? – Dennis 2012-04-07 12:22:38

+0

你爲什麼要設置IsHitTestVisible?你沒有試過嗎? – 2012-04-07 12:38:42

+0

我第一次嘗試沒有設置它,它也閃爍...... – 2012-04-07 12:53:29

回答

0

閱讀評論後,我相信你使用的是不正確的事件;一個MouseMove事件將不斷觸發,每次彈出窗口顯示/隱藏或閃爍。

要使用MouseEnterMouseLeave事件。

+0

我已經試過了,但我必須檢查鼠標的數據點值是否已經改變或者不是(現在你可以說將它附加到數據點的MouseEnter或MouseLeave中,但是作爲LineSeries,我將數據點的寬度/高度設置爲0,我只需要該行。無論如何,在MouseMove '我在「重新打開」之前檢查PopUp的數值是不同的...... – 2012-04-07 14:36:59

+0

有趣的事情當鼠標在工具提示上時,'ChartMouseLeave'(我設置'popup.IsOpen =「False」'是trigger ... – 2012-04-07 14:47:05

+0

你使用什麼圖表中間件? – Dennis 2012-04-07 14:48:08

2

我也遇到類似的問題,同時使用MouseEnterMouseLeave事件。在WPF上有一個奇怪的行爲MouseEnter事件,不知道它是否是一個錯誤。當您從上方考慮輸入項目時,會發生閃爍。從任何其他方向輸入項目都會給您一個平滑的彈出窗口。所以爲了避免它,我刪除了:

AllowsTransparency = True 

部分。

編輯:

雖然仍無法找到一個完美的行爲,我的需要,我想通了,這實際上不是一個問題,問題由Scott Hanselman在here

描述然而我不是能夠將問題與我的問題進行比較並整理出來。無論如何,爲了獲得動畫功能,我想出了一個解決方案,通過檢查鼠標的當前位置,至少減少Popup控件的額外打開或關閉。我定義的變量

Point currPoint = new Point(); 

然後在MouseEnter事件或處理程序:在MouseLeave事件或處理

ListViewItem listViewItem = e.Source as ListViewItem;   
     if(currPoint!=e.GetPosition(listViewItem)) 
      compToStrategyVM.OpenPopup(listViewItem, listViewPopup); 

同理:

ListViewItem listViewItem = e.Source as ListViewItem; 
     if (currPoint != e.GetPosition(listViewItem)) 
      compToStrategyVM.ClosePopup(listViewPopup); 

這裏compToStrategyVM指的是我的視圖模式和listViewPopup指的是Popup控件的名稱。雖然這個問題仍然存在,但通過這種方法,閃爍效應已經減少到相當大的一部分。

+0

唯一的缺點是你不能使用彈出式動畫需要將上述變量設置爲'true'的功能 – sm2mafaz 2014-09-22 14:29:23