?在ListView列表中,存在多個項目,每個項目都需要右鍵菜單進行操作。這時一般情況下定義的采用以下方式:即在模板中定義的控件內(nèi)(在當(dāng)前示例中是Border),定義一個ContextMenu。Command在ViewModel中定義。文章來源地址http://www.zghlxwxcb.cn/news/detail-458291.html
<Grid>
<Grid.Resources>
<ViewModel:BindingProxy x:Key="BindingProxy" Data="{Binding}"/>
</Grid.Resources>
<ListView ItemsSource="{Binding Records}">
<ListView.ItemTemplate>
<DataTemplate>
<!--有右鍵菜單情況下,父級控件必須有背景色,否則在沒有控件的地方右鍵無法彈出菜單。-->
<Border Margin="2,0,2,0" Name="bd" Background="Transparent">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="刪除" Icon="???" Command="{Binding DeleteCmd}" />
</ContextMenu>
</Border.
文章來源:http://www.zghlxwxcb.cn/news/detail-458291.html
到了這里,關(guān)于WPF ContextMenu 的綁定和傳參問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!