我有一个datagrid,其中包含DatagridTemplateColumn中的超链接,如下所示:
<DataGridTemplateColumn Width="170" SortMemberPath="Joueur.EtatCivil.Joueur_nom" CanUserReorder="False" CanUserResize="True" Header="">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate />
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource DatagridCellHyperlinkStyle}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Padding="{TemplateBinding Padding}" Width="Auto" VerticalAlignment="Center" SnapsToDevicePixels="True">
<TextBlock Foreground="{TemplateBinding Foreground}" Width="Auto" TextTrimming="CharacterEllipsis">
<Hyperlink IsEnabled="{TemplateBinding IsEnabled}">
<InlineUIContainer TextDecorations="{Binding Path=TextDecorations, RelativeSource={RelativeSource AncestorType=TextBlock}}" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=TextBlock}}">
<ContentPresenter Content="{Binding DataContext.Joueur.EtatCivil.NomComplet, RelativeSource={RelativeSource AncestorType=DataGridRow}}"/>
</InlineUIContainer>
<Hyperlink.Style>
<Style TargetType="Hyperlink" BasedOn="{StaticResource HyperlinkStyle}">
<EventSetter Event="Hyperlink.Click" Handler="ClickEvent" />
<EventSetter Event="Hyperlink.MouseEnter" Handler="MouseOverEvent" />
<EventSetter Event="Hyperlink.MouseLeave" Handler="ClicJoueurMouseLeaveEvent" />
</Style>
</Hyperlink.Style>
</Hyperlink>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
这样可以正常工作,但是当我只是在很短的时间内(或者可能是<0.5秒)移动光标时,我会遇到麻烦。
My MouseEnterEvent调用名为“Show();”的方法我的MouseLeaveEvent是一个名为“Hide();”
的方法这个显示/隐藏一个小弹出窗口向用户显示更多数据。问题是我的show();方法更新Wpf工具包图表,似乎无法使用此频率更新(在0.5秒内10次)。绑定似乎“崩溃”,永远不会再起作用。 这帮助了我:Binding update adds news series to WPF Toolkit chart (instead of replacing/updating series))
我像这样更新我的图表:
this.colonnes.ItemsSource = null;
_DataGraph = new ObservableCollection<GraphiqueValeurs>();
_DataGraph.Add(new GraphiqueValeurs(value, "my string");
this.colonnes.ItemsSource = _DataGraph;
this.colonnes.UpdateLayout();
使用以下xaml:
<chartingToolkit:Chart VerticalAlignment="Top" HorizontalAlignment="Center" FontFamily="/BPM2015;component/#Open Sans Condensed" BorderBrush="Transparent" Name="columnChart" Title="Column Series Demo" Foreground="{DynamicResource CouleurTexte}" >
<chartingToolkit:ColumnSeries Name="colonnes" Foreground="{DynamicResource CouleurTexte}" DependentValueBinding="{Binding Valeur}"
IndependentValueBinding="{Binding Name}"
DataPointStyle="{StaticResource ColorByPreferenceColumn}"
>
<chartingToolkit:ColumnSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis Orientation="Y" Minimum="0" Maximum="20" Title="" Foreground="Transparent" ShowGridLines="True">
<chartingToolkit:LinearAxis.MajorTickMarkStyle>
<Style TargetType="Line">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</chartingToolkit:LinearAxis.MajorTickMarkStyle>
</chartingToolkit:LinearAxis>
</chartingToolkit:ColumnSeries.DependentRangeAxis>
</chartingToolkit:ColumnSeries>
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0" />
<Setter Property="Height" Value="0" />
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.TitleStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0" />
<Setter Property="Height" Value="0" />
</Style>
</chartingToolkit:Chart.TitleStyle>
所以我的问题是:如何避免所有这些快速鼠标输入?如果光标在超链接上没有保持至少0.4秒,我想避免使用mouseEnter函数来调用“Show()”方法。
我怎么能这样做?
这个
谢谢
答案 0 :(得分:1)
您可以使用DispatcherTimer
添加延迟来调用您的函数,并将其与bool
处理程序中设置为true
的{{1}}标志相结合并设置到MouseEnter
处理程序中的false
。试试这个:
MouseLeave
...
private DispatcherTimer timer = new DispatcherTimer();
private isMouseOver = false;
...
timer.Interval = TimeSpan.FromMilliseconds(400);
timer.Tick += Timer_Tick;