2015-10-15 587 views
0

我有一个上下文菜单,它曾经是一个弹出式菜单。当我第一次加载程序时,上下文菜单是空的,因为菜单项被绑定到列表。但是,如果我加载程序并右键单击第一个列表是好的,然后我可以去左键单击并出现列表。我将展示图像,以帮助我的描述:上下文菜单左键单击

左键点击后

enter image description here

谁能帮助第一

enter image description here

右击第一个也是左键点击我明白为什么会发生这种情况,以及如何解决它?

编辑 - XAML中

<DataTemplate x:Key="AddNodeTemplate"> 
     <StackPanel> 
      <Button x:Name="buttonAdd"> 
       <Button.Style> 
        <Style TargetType="{x:Type Button}"> 
         <Style.Triggers> 
          <EventTrigger RoutedEvent="Click"> 
           <EventTrigger.Actions> 
            <BeginStoryboard> 
             <Storyboard> 
              <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen"> 
               <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/> 
              </BooleanAnimationUsingKeyFrames> 
             </Storyboard> 
            </BeginStoryboard> 
           </EventTrigger.Actions> 
          </EventTrigger> 
         </Style.Triggers> 
         <Setter Property="Template"> 
          <Setter.Value> 
           <ControlTemplate TargetType="Button"> 
            <Border BorderThickness="0"> 
             <ContentPresenter/> 
            </Border> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </Button.Style> 
       <Canvas> 
        <Image Source="Images/bkg_plus.png" Width="30" Height="30" Panel.ZIndex="5"/> 
        <Rectangle Stroke="LightGray" StrokeDashArray="2 2" Width="120" Height="30" VerticalAlignment="Center" Margin="0,0,0,0" 
       Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type syncfusion:Node}}}"> 
         <Rectangle.Fill> 
          <SolidColorBrush Color="LightGray"/> 
         </Rectangle.Fill> 
        </Rectangle> 
        <TextBlock Text="Add Property" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="30 10 0 0" Background="Transparent"/> 
       </Canvas> 
       <Button.ToolTip> 
        <ToolTip> 
         <Label Content="Add Property"/> 
        </ToolTip> 
       </Button.ToolTip> 
       <Button.ContextMenu> 
        <ContextMenu ItemsSource="{Binding AvailableProperties}"> 
         <ContextMenu.Resources> 
          <Style TargetType="MenuItem"> 
           <Setter Property="Header" Value="{Binding Path=Name}"/> 
           <Setter Property="ToolTip" Value="{Binding Path=ToolTips}"/> 
           <Setter Property="Command" Value="{Binding Path=Command}"/> 
           <Setter Property="CommandParameter" Value="{Binding Path=CommandParameter}"/> 
           <!--<Setter Property="Icon" Value="{Binding Icon , Converter={StaticResource ImageToSourceConverter}"/>--> 
          </Style> 
         </ContextMenu.Resources> 
        </ContextMenu> 
       </Button.ContextMenu> 
      </Button> 
     </StackPanel> 
    </DataTemplate> 

新结果

好了,所以这是现在当我点击左侧第一

enter image description here

所以我发生了什么尝试使用弹出和有在这里面的一个菜单,这是我的XAML的结果,现在唯一的问题是我想改变高亮的背景,当鼠标悬停在“添加现有属性”时,有谁知道如何做到这一点,并将菜单移动在右边,我会发布图片多达解释正下方弹出,而不是像上面的照片,我希望背景是蓝色的,而不是灰色的背景为右

<DataTemplate x:Key="AddNodeTemplate"> 
     <Border BorderThickness="1" Background="#F7F7F7"> 
      <Border.BorderBrush> 
       <DrawingBrush Viewport="8,8,8,8" ViewportUnits="Absolute" TileMode="Tile"> 
        <DrawingBrush.Drawing> 
         <DrawingGroup> 
          <GeometryDrawing Brush="#F7F7F7"> 
           <GeometryDrawing.Geometry> 
            <GeometryGroup> 
             <RectangleGeometry Rect="0,0,50,50"/> 
             <RectangleGeometry Rect="50,50,50,50"/> 
            </GeometryGroup> 
           </GeometryDrawing.Geometry> 
          </GeometryDrawing> 
         </DrawingGroup> 
        </DrawingBrush.Drawing> 
       </DrawingBrush> 
      </Border.BorderBrush> 
      <StackPanel> 
      <ToggleButton Height="30" Width="120" Style="{StaticResource ChromelessToggleButton}" x:Name="toggleButtonAdd" IsHitTestVisible="{Binding ElementName=Popup, Path=IsOpen, Mode=OneWay, Converter={StaticResource OppositeBooleanConverter}}"> 
       <ToggleButton.ToolTip> 
        <ToolTip> 
         <Label Content="Add Property"/> 
        </ToolTip> 
       </ToggleButton.ToolTip> 
      </ToggleButton> 
      <Popup IsOpen="{Binding IsChecked, ElementName=toggleButtonAdd}" x:Name="Popup" StaysOpen="False" Placement="Right"> 
       <Border BorderBrush="Black" BorderThickness="0" Background="#F7F7F7"> 
         <StackPanel Margin="5,10,5,5" Orientation="Horizontal"> 
          <Menu Background="#F7F7F7"> 
           <Menu.ItemsPanel> 
            <ItemsPanelTemplate> 
             <VirtualizingStackPanel Orientation="Vertical"/> 
            </ItemsPanelTemplate> 
           </Menu.ItemsPanel> 
          <MenuItem Header="Add Exisiting Properties"> 
           <ListBox BorderBrush="Black" BorderThickness="0" Background="Transparent" Margin="5" Padding="4" Width="130" 
           ItemsSource="{Binding Path=AvailableProperties}" SelectionChanged="Selector_OnSelectionChanged"> 
            <ListBox.ItemContainerStyle> 
             <Style TargetType="ListBoxItem"> 
              <Style.Triggers> 
               <Trigger Property="IsSelected" Value="True"> 
                <Setter Property="FontWeight" Value="Bold"/> 
                <Setter Property="Background" Value="Transparent"/> 
                <Setter Property="Foreground" Value="Black"/> 
               </Trigger> 
               <Trigger Property="IsMouseOver" Value="True"> 
                <Setter Property="Background" Value="#5194C7"/> 
                <Setter Property="FontWeight" Value="Bold"/> 
               </Trigger> 
              </Style.Triggers> 
             </Style> 
            </ListBox.ItemContainerStyle> 
            <ListBox.ItemTemplate> 
            <DataTemplate> 
              <StackPanel Orientation="Horizontal"> 
               <Image Source="{Binding Icon, Converter={StaticResource ImageToSourceConverter}}" Width="12" Height="12" Margin="3" VerticalAlignment="Center"/> 
               <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/> 
              </StackPanel> 
            </DataTemplate> 
            </ListBox.ItemTemplate> 
           </ListBox> 
          </MenuItem> 
           <MenuItem Header="Upscale Well logs">   
           </MenuItem> 
           <MenuItem Header="Upscale well_top attributes"> 
           </MenuItem> 
           <MenuItem Header="Upscale point attributes"> 
           </MenuItem> 
           <MenuItem Header="Calculate"> 
           </MenuItem> 
          </Menu> 
        </StackPanel> 
       </Border> 
      </Popup> 
     </StackPanel> 
     </Border> 
    </DataTemplate> 

图片菜单在下面的图片中

enter image description here

+0

删除你的画布和检查。 –

+0

试试这种风格将图像添加到您的按钮背景。 在资源中添加

+0

删除画布和添加样式只是给了我另一个黑色屏幕:( –

回答

1

您可以通过添加一个Context MenuStyle像下面这样做,我不认为它必要的ListBox里面去MenuItem

<Button.ContextMenu> 
    <ContextMenu ItemsSource="{Binding AvailableProperties}"> 
    <ContextMenu.Resources> 
     <Style TargetType="MenuItem">        
      <Setter Property="Header" Value="{Binding Path=Name}"/> 
      <Setter Property="ToolTip" Value="{Binding Path=ToolTips}"/> 
      <Setter Property="Command" Value="{Binding Path=Command}"/> 
      <Setter Property="CommandParameter" Value="{Binding Path=CommandParameter}"/> 
      <Setter Property="Icon" Value="{Binding Icon , Converter={StaticResource ImageToSourceConverter}"/> 
     </Style> 
    </ContextMenu.Resources>      
    </ContextMenu> 
</Button.ContextMenu> 
+0

当我这样做了我的网页只是完全黑色:(我没有错误什么都没有,只是一个黑色的屏幕 –

+0

当我尝试,我得到2个非常小的矩形,再次右键单击作品完美,当它左击后它的工作,做你需要一个屏幕截图,以了解发生了什么? –

+0

我不知道为什么,但试图在任何地方进行研究,没有运气来解释 –

相关问题