0
所以我一直在嘗試添加一個上下文菜單到我的listviewitems,但我無法弄清楚。 我設法弄清楚如何爲lsitview控件做到這一點,但我似乎無法弄清楚如何爲實際的listviewitems做到這一點。如何添加一個contextmenu到我在WPF中的listviewitems?
我這樣做
<ContextMenu>
<MenuItem Header="Remove"/>
</ContextMenu>
要我listviewcontrol其中添加文本菜單給它但那不是我想要的,我想它的listviewitems。
<ListView Margin="10,36,520,10" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderBrush="Black" Padding="-1, -1, 1, 0" Background="Transparent" BorderThickness="1.000001" Name="lvUsers" Style="{DynamicResource ListViewStyle1}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border
BorderBrush="Transparent"
BorderThickness="0"
Background="{TemplateBinding Background}">
<GridViewRowPresenter HorizontalAlignment="Stretch" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Width="Auto" Margin="0" Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#696969" />
<Setter Property="BorderBrush" Value="#696969" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#696969" />
<Setter Property="BorderBrush" Value="#696969" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle1}">
<GridViewColumn x:Name="GridViewColumnName" Header="Name" Width="165">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="Image_GridViewColumnName" Width="16" Height="16" Source="C:\Users\developer\source\repos\PortforwardWPF\PortforwardWPF\Images\minecraft.png" />
<Label Content="{Binding Username}" Visibility="Visible" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
喔!驚人!謝謝你,先生! –