![](/img/trans.png)
[英]How can my Outlook add-in get the Attachment object the user is right-clicking in my custom menu?
[英]How to show context menu on a ListBoxItem template on a grid when right-clicking outside the contents of it?
你好,
我有一個ListBox.ItemTemplate
(顯然包含一個DataTemplate
),其中包含一個本身包含Label
的Grid
。
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>
謝謝 !
將標簽的HorizontalAlignment更改為Stretch,以使其充滿整個網格單元。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.