WP7 Context Menu Hidden Delay Found

After looking for all the timers in the ContextMenu inside the toolkit source code, I changed:

  1. ThresholdDuration
  2. ZoomDuration
  3. Extracted the style to avoid the duration times.

Without success, now I found where is the hidden delay.

In the:


internal DependencyObject Owner

There is a hidden intrinsec delay at the event Hold!!:


GestureListener listener = GestureService.GetGestureListener(ownerFrameworkElement);
listener.Hold += new EventHandler(HandleOwnerHold);

Now I have to change the event from Hold to GestureBegin + Tap, and the result is using Delay in ms (Delays below 350 can make issues):


ContextMenuExt>
<tk:ContextMenuExt Delay="500" IsZoomEnabled="True" Style="{StaticResource ContextMenuStyle}">
MenuItemExt Header="Add" Style="{StaticResource MenuItemStyle}" Click="MenuItem_Click" />
</tk:ContextMenuExt>
</tk:ContextMenuExtService.ContextMenuExt>

The download of the extension is here, just rename wmv yo 7z.

The demo using the dll here, the same rename wmv to 7z.

Apart from that, you have to add the styles in order to work fine (It is included in the second link):


<Style x:Key="ContextMenuStyle" TargetType="t2:ContextMenuExt">
<Setter Property="Background" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneBackgroundBrush}"/>
<Setter Property="Padding" Value="0 14 0 16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="t2:ContextMenuExt">
<StackPanel RenderTransformOrigin="0.5,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisibilityStates">
<VisualState x:Name="Open">
<Storyboard>
<DoubleAnimation Duration="0" Storyboard.TargetName="ScaleX" Storyboard.TargetProperty="ScaleX" To="1"/>
<DoubleAnimation Duration="0" Storyboard.TargetName="ScaleY" Storyboard.TargetProperty="ScaleY" To="1"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Closed">
<Storyboard>
<DoubleAnimation Duration="0" Storyboard.TargetName="ScaleX" Storyboard.TargetProperty="ScaleX" To="0"/>
<DoubleAnimation Duration="0" Storyboard.TargetName="ScaleY" Storyboard.TargetProperty="ScaleY" To="0"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel.RenderTransform>
<ScaleTransform x:Name="ScaleX"/>
</StackPanel.RenderTransform>
<Rectangle Height="2" Fill="{TemplateBinding BorderBrush}"/>
<Rectangle Height="2" Fill="{TemplateBinding Background}"/>
<StackPanel Background="{TemplateBinding Background}" RenderTransformOrigin="0.5,0">
<StackPanel.RenderTransform>
<ScaleTransform x:Name="ScaleY"/>
</StackPanel.RenderTransform>
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
<Rectangle Height="2" Fill="{TemplateBinding BorderBrush}"/>
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="MenuItemStyle" TargetType="t2:MenuItemExt">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneBackgroundBrush}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiLight}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeLarge}"/>
<Setter Property="Padding" Value="25 12 25 12"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="t2:MenuItemExt">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" Storyboard.TargetName="Presenter" Storyboard.TargetProperty="Opacity" To="0.5"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="Presenter" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" Margin="{TemplateBinding Padding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s