2016-05-17 29 views
-1

我在上下文菜單中有項目,項目之間有更多空間。我嘗試了很多方式來創建物品容器,將邊距減小到0,填充爲零。沒有什麼works.May任何人都可以幫助我解決這個問題。如何刪除UWP中的上下文菜單項之間的空間

<Style TargetType="local:ContextMenu"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="local:ContextMenu">      
       <Border BorderThickness="1" BorderBrush="LightGray"> 
        <ListView x:Name="PART_ContextMenuListView" BorderThickness="0" 
           ItemContainerStyle="{StaticResource ListViewItemStyle1}"       
           Background="White" >       
        </ListView> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem"> 
    <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/> 
    <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/> 
    <Setter Property="Margin" Value="0"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="Height" Value="30"/> 
    <Setter Property="TabNavigation" Value="Local"/> 
    <Setter Property="IsHoldingEnabled" Value="True"/>   
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
    <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListViewItem"> 
       <Border x:Name="OuterContainer"> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal"/> 
          <VisualState x:Name="PointerOver"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBorder"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SelectionBackground"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedPointerOverBackgroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="SelectedBorder"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedPointerOverBorderThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames>           
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Pressed"> 
           <Storyboard> 
            <PointerDownThemeAnimation TargetName="ContentContainer"/> 
           </Storyboard> 
          </VisualState>         
          <VisualState x:Name="Disabled"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="{StaticResource ListViewItemDisabledThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="FocusStates"> 
          <VisualState x:Name="Focused"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisual"/>--> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Unfocused"/> 
          <VisualState x:Name="PointerFocused"/> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="SelectionHintStates"> 
          <VisualStateGroup.Transitions> 
           <VisualTransition GeneratedDuration="0:0:0.65" To="NoSelectionHint"/> 
          </VisualStateGroup.Transitions> 
          <VisualState x:Name="VerticalSelectionHint"> 
           <Storyboard> 
            <SwipeHintThemeAnimation ToHorizontalOffset="0" TargetName="SelectionBackground" ToVerticalOffset="15"/> 
            <SwipeHintThemeAnimation ToHorizontalOffset="0" TargetName="ContentBorder" ToVerticalOffset="15"/> 
            <SwipeHintThemeAnimation ToHorizontalOffset="0" TargetName="SelectedBorder" ToVerticalOffset="15"/> 
            <!--<SwipeHintThemeAnimation ToHorizontalOffset="0" TargetName="SelectedCheckMark" ToVerticalOffset="15"/>--> 
            <!--<DoubleAnimationUsingKeyFrames Duration="0:0:0.500" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyph"> 
             <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0.5"/> 
             <DiscreteDoubleKeyFrame KeyTime="0:0:0.500" Value="0"/> 
            </DoubleAnimationUsingKeyFrames>--> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="HorizontalSelectionHint"> 
           <Storyboard> 
            <SwipeHintThemeAnimation ToHorizontalOffset="-23" TargetName="SelectionBackground" ToVerticalOffset="0"/> 
            <SwipeHintThemeAnimation ToHorizontalOffset="-23" TargetName="ContentBorder" ToVerticalOffset="0"/> 
            <SwipeHintThemeAnimation ToHorizontalOffset="-23" TargetName="SelectedBorder" ToVerticalOffset="0"/> 
            <!--<SwipeHintThemeAnimation ToHorizontalOffset="-23" TargetName="SelectedCheckMark" ToVerticalOffset="0"/>--> 
            <DoubleAnimationUsingKeyFrames Duration="0:0:0.500" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyph"> 
             <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0.5"/> 
             <DiscreteDoubleKeyFrame KeyTime="0:0:0.500" Value="0"/> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="NoSelectionHint"/> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="SelectionStates"> 
          <VisualState x:Name="Unselecting"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyphBorder"/>--> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Unselected"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyphBorder"/>--> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="UnselectedPointerOver"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyphBorder"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="UnselectedSwiping"> 
           <Storyboard> 
            <!--<DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectingGlyph"/>--> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyphBorder"/>--> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Selecting"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBorder"/> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectingGlyph"/>--> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HintGlyphBorder"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Selected"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBorder"/> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedCheckMark"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="SelectedSwiping"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBorder"/> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedCheckMark"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="SelectedUnfocused"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectionBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBorder"/> 
            <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedCheckMark"/>--> 
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter"> 
             <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListViewItemSelectedForegroundThemeBrush}"/> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="DragStates"> 
          <VisualStateGroup.Transitions> 
           <VisualTransition GeneratedDuration="0:0:0.2" To="NotDragging"/> 
          </VisualStateGroup.Transitions> 
          <VisualState x:Name="NotDragging"/> 
          <VisualState x:Name="Dragging"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="{StaticResource ListViewItemDragThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InnerDragContent"/> 
            <DragItemThemeAnimation TargetName="InnerDragContent"/> 
            <!--<FadeOutThemeAnimation TargetName="SelectedCheckMarkOuter"/>--> 
            <FadeOutThemeAnimation TargetName="SelectedBorder"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="DraggingTarget"> 
           <Storyboard> 
            <DropTargetItemThemeAnimation TargetName="OuterContainer"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="MultipleDraggingPrimary"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="MultiArrangeOverlayBackground"/> 
            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="MultiArrangeOverlayText"/> 
            <DoubleAnimation Duration="0" To="{StaticResource ListViewItemDragThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentBorder"/> 
            <FadeInThemeAnimation TargetName="MultiArrangeOverlayBackground"/> 
            <FadeInThemeAnimation TargetName="MultiArrangeOverlayText"/> 
            <DragItemThemeAnimation TargetName="ContentBorder"/> 
            <FadeOutThemeAnimation TargetName="SelectionBackground"/> 
            <!--<FadeOutThemeAnimation TargetName="SelectedCheckMarkOuter"/>--> 
            <FadeOutThemeAnimation TargetName="SelectedBorder"/> 
            <FadeOutThemeAnimation TargetName="PointerOverBorder"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="MultipleDraggingSecondary"> 
           <Storyboard> 
            <FadeOutThemeAnimation TargetName="ContentContainer"/> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="ReorderHintStates"> 
          <VisualStateGroup.Transitions> 
           <VisualTransition GeneratedDuration="0:0:0.2" To="NoReorderHint"/> 
          </VisualStateGroup.Transitions> 
          <VisualState x:Name="NoReorderHint"/> 
          <VisualState x:Name="BottomReorderHint"> 
           <Storyboard> 
            <DragOverThemeAnimation Direction="Bottom" ToOffset="{StaticResource ListViewItemReorderHintThemeOffset}" TargetName="ReorderHintContent"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="TopReorderHint"> 
           <Storyboard> 
            <DragOverThemeAnimation Direction="Top" ToOffset="{StaticResource ListViewItemReorderHintThemeOffset}" TargetName="ReorderHintContent"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="RightReorderHint"> 
           <Storyboard> 
            <DragOverThemeAnimation Direction="Right" ToOffset="{StaticResource ListViewItemReorderHintThemeOffset}" TargetName="ReorderHintContent"/> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="LeftReorderHint"> 
           <Storyboard> 
            <DragOverThemeAnimation Direction="Left" ToOffset="{StaticResource ListViewItemReorderHintThemeOffset}" TargetName="ReorderHintContent"/> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="DataVirtualizationStates"> 
          <VisualState x:Name="DataAvailable"/> 
          <VisualState x:Name="DataPlaceholder"> 
           <Storyboard> 
            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PlaceholderTextBlock"> 
             <DiscreteObjectKeyFrame KeyTime="0"> 
              <DiscreteObjectKeyFrame.Value> 
               <Visibility>Visible</Visibility> 
              </DiscreteObjectKeyFrame.Value> 
             </DiscreteObjectKeyFrame> 
            </ObjectAnimationUsingKeyFrames> 
            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PlaceholderRect"> 
             <DiscreteObjectKeyFrame KeyTime="0"> 
              <DiscreteObjectKeyFrame.Value> 
               <Visibility>Visible</Visibility> 
              </DiscreteObjectKeyFrame.Value> 
             </DiscreteObjectKeyFrame> 
            </ObjectAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Grid x:Name="ReorderHintContent" Background="Transparent" Margin="0"> 
         <Path x:Name="SelectingGlyph" Data="F1 M133.1,17.9 L137.2,13.2 L144.6,19.6 L156.4,5.8 L161.2,9.9 L145.6,28.4 z" Fill="{StaticResource ListViewItemCheckSelectingThemeBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right" Height="13" Margin="0,9.5,9.5,0" Opacity="0" Stretch="Fill" VerticalAlignment="Top" Width="15"/> 
         <Border x:Name="HintGlyphBorder" HorizontalAlignment="Right" Height="0" Margin="0" Opacity="0" VerticalAlignment="Top" Width="40"> 
          <Path x:Name="HintGlyph" Data="F1 M133.1,17.9 L137.2,13.2 L144.6,19.6 L156.4,5.8 L161.2,9.9 L145.6,28.4 z" Fill="{StaticResource ListViewItemCheckHintThemeBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right" Height="13" Margin="0,5.5,5.5,0" Opacity="0" Stretch="Fill" VerticalAlignment="Top" Width="15"/> 
         </Border> 
         <Border x:Name="ContentContainer" BorderThickness="0" Margin="0" Padding="0"> 
          <Grid x:Name="InnerDragContent" Margin="0"> 
           <!--<Rectangle x:Name="PointerOverBorder" Fill="{StaticResource ListViewItemPointerOverBackgroundThemeBrush}" IsHitTestVisible="False" Margin="-5" Opacity="0"/> 
           <Rectangle x:Name="FocusVisual" IsHitTestVisible="False" Opacity="0" Stroke="{StaticResource ListViewItemFocusBorderThemeBrush}" Margin="-5" StrokeThickness="2"/>--> 
           <Rectangle x:Name="SelectionBackground" Fill="{StaticResource ListViewItemSelectedBackgroundThemeBrush}" Margin="0" Opacity="0"/> 
           <Border x:Name="ContentBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="Beige" Margin="-5"> 
            <Grid> 
             <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
             <TextBlock x:Name="PlaceholderTextBlock" Foreground="{x:Null}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" Opacity="0" Text="Xg"/> 
             <Rectangle x:Name="PlaceholderRect" Fill="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" IsHitTestVisible="False" Visibility="Collapsed"/> 
             <Rectangle x:Name="MultiArrangeOverlayBackground" Fill="{StaticResource ListViewItemDragBackgroundThemeBrush}" IsHitTestVisible="False" Opacity="0"/> 
            </Grid> 
           </Border> 
           <Rectangle x:Name="SelectedBorder" IsHitTestVisible="False" Margin="0" Opacity="0" Stroke="{StaticResource ListViewItemSelectedBackgroundThemeBrush}" StrokeThickness="{StaticResource ListViewItemSelectedBorderThemeThickness}"/> 
           <!--<Border x:Name="SelectedCheckMarkOuter" HorizontalAlignment="Right" IsHitTestVisible="False" Margin="4" VerticalAlignment="Top"> 
            <Grid x:Name="SelectedCheckMark" Height="40" Opacity="0" Width="40"> 
             <Path x:Name="SelectedEarmark" Data="M0,0 L40,0 L40,40 z" Fill="{StaticResource ListViewItemSelectedBackgroundThemeBrush}" Stretch="Fill"/> 
             <Path Data="F1 M133.1,17.9 L137.2,13.2 L144.6,19.6 L156.4,5.8 L161.2,9.9 L145.6,28.4 z" Fill="{StaticResource ListViewItemCheckThemeBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right" Height="13" Margin="0,5.5,5.5,0" Stretch="Fill" VerticalAlignment="Top" Width="15"/> 
            </Grid> 
           </Border>--> 
           <TextBlock x:Name="MultiArrangeOverlayText" Foreground="{StaticResource ListViewItemDragForegroundThemeBrush}" FontSize="26.667" FontFamily="{StaticResource ContentControlThemeFontFamily}" IsHitTestVisible="False" Margin="0" Opacity="0" TextWrapping="Wrap" Text="{Binding TemplateSettings.DragItemsCount, RelativeSource={RelativeSource Mode=TemplatedParent}}" TextTrimming="WordEllipsis"/> 
          </Grid> 
         </Border> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#D5E1F2"/> 
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#D5E1F2"/> 
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#D5E1F2"/> 

而在代碼隱藏

var cuticon = resources["CutIcon"] as ImageSource; 
     var copyicon = resources["CopyIcon"] as ImageSource; 
     var pasteoptionsicon = resources["PasteOptionsIcon"] as ImageSource; 
     var pasteallicon = resources["PasteAllIcon"] as ImageSource; 
     var pastevalueicon = resources["PasteValueIcon"] as ImageSource; 
     var pasteformulaicon = resources["PasteFormulaIcon"] as ImageSource; 
     var pasteformaticon = resources["PasteFormatIcon"] as ImageSource; 
     var pastevalueformaticon = resources["PasteValueFormatIcon"] as ImageSource; 
     var insertcommenticon = resources["InsertCommentIcon"] as ImageSource; 
     var editcommenticon = resources["EditCommentIcon"] as ImageSource; 
     var deletecommenticon = resources["DeleteCommentIcon"] as ImageSource; 
     var hyperlinkicon = resources["HyperlinkIcon"] as ImageSource; 
     var removehyperlinkicon = resources["RemoveHyperlinkIcon"] as ImageSource; 
     var formatcellsicon = resources["FormatCellsIcon"] as ImageSource; 

     var ribbonbuttonstyle = new Style(typeof(SfRibbonButton)); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.WidthProperty, "220")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.HeightProperty, "30")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.FontFamilyProperty, "Caliber")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.BackgroundProperty, "Transparent")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.SizeModeProperty, "Large")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.FontWeightProperty, "Normal")); 
     ribbonbuttonstyle.Setters.Add(new Setter(SfRibbonButton.MarginProperty, "0")); 

     var cutbutton = new SfRibbonButton 
     { 
      Command = this.Commands.Cut, 
      Name = "CutButton", 
      Label = GridResourceWrapper.Cut, 
      Margin = new Thickness(0), 
      BorderThickness = new Thickness(0), 
      Icon = cuticon, 
     }; 
     cutbutton.Height = 30; 
     var copybutton = new SfRibbonButton 
     { 
      Command = this.Commands.Copy, 
      Name = "CopyButton", 
      Label = GridResourceWrapper.Copy, 
      Margin = new Thickness(0), 
      BorderThickness = new Thickness(0), 
      Icon = copyicon, 
      Style = ribbonbuttonstyle, 
     }; 
     var pasteoptionstitlebutton = new SfRibbonButton 
     { 
      Name = "PasteOptionsTitleButton", 
      Label = GridResourceWrapper.Context_PasteOptions, 
      Height = 26, 
      BorderThickness = new Thickness(0), 
      Icon = pasteoptionsicon, 
      Style = ribbonbuttonstyle, 
      FontWeight = Windows.UI.Text.FontWeights.Bold, 
      IsHitTestVisible = false, 
      //Padding = new Thickness(0, 5, 0, 2) 
     }; 
+0

請提供我添加的代碼SampleContextMenu元素 –

回答

0

您還沒有提供任何代碼,但您可以創建自定義彈出的右鍵菜單。 This GitHub sample可以幫助你。如果短期內,您可以根據需要添加到頁面資源彈出和改變風格:

<Page.Resources> 
    <MenuFlyout x:Key="SampleContextMenu"> 
     <MenuFlyoutItem Text="Open" Tag="&#xE1A5;" /> 
     <MenuFlyoutItem Text="Print" Tag="&#xE2F6;" /> 
     <MenuFlyoutItem Text="Delete" Tag="&#xE10A;" /> 
     <MenuFlyoutSubItem Text="Other"> 
      <MenuFlyoutItem Text="Sort by" /> 
      <MenuFlyoutItem Text="Name" /> 
      <MenuFlyoutItem Text="Date" /> 
      <MenuFlyoutItem Text="Size" /> 
     </MenuFlyoutSubItem> 
    </MenuFlyout> 
</Page.Resources> 

而且裏面CS:

 protected override void OnRightTapped(RightTappedRoutedEventArgs e) 
    { 
     ShowContextMenu(null, e.GetPosition(null)); 
     e.Handled = true; 

     base.OnRightTapped(e); 
    } 

    private void ShowContextMenu(UIElement target, Point offset) 
    { 
     var MyFlyout = this.Resources["SampleContextMenu"] as MenuFlyout; 
     MyFlyout.ShowAt(target, offset); 
    } 
+0

也XAML。我需要減少項目之間的間距 – Dinesh

+0

目前在您的ListViewItemStyle1模板中,我可以看到一些邊距和高度屬性。但是如果你改變了他們,你的控制可能會看起來很難看。我建議你最好在Blend中打開你的模板。在這種情況下,您將看到所有更改 –

+0

我已刪除間距,但另一個問題是鼠標懸停在項目上時,整個範圍不會突出顯示只有特定範圍的背景已更改 – Dinesh

相關問題