簡體   English   中英

右鍵單擊網格的ListBoxItem模板的內容時,如何顯示上下文菜單?

[英]How to show context menu on a ListBoxItem template on a grid when right-clicking outside the contents of it?

你好,

我有一個ListBox.ItemTemplate (顯然包含一個DataTemplate ),其中包含一個本身包含LabelGrid

Grid具有Grid.ContextMenu 問題是,僅當我右鍵單擊Label時才顯示ContextMenu 不在外面

如果您不了解,這是一張顯示問題的圖像(但我確定您已經知道了;)!)

這是代碼:

<ListBox.ItemTemplate>
   <DataTemplate>
      <Grid Margin="0,0,0,1">
         <Grid.ContextMenu>
            <ContextMenu>
               <MenuItem CommandParameter="{Binding}" Command="{Binding Source={x:Reference window}, Path=DataContext.DeleteCommand}" Header="Supprimer">
                  <MenuItem.Icon>
                     <Image Source="/SchoolTools.Teacher;component/Images/DeleteIcon.png" />
                  </MenuItem.Icon>
               </MenuItem>
            </ContextMenu>
         </Grid.ContextMenu>
         <Label Content="{Binding ClassYear}" Padding="0" 
          HorizontalAlignment="Center" />
      </Grid>
   </DataTemplate>
</ListBox.ItemTemplate>

謝謝 !

將標簽的Horizo​​ntalAlignment更改為Stretch,以使其充滿整個網格單元。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM