[英]How to get selectedItem from ListView from a button click in the listView Item
我有一個帶有按鈕的列表視圖項,並在對象上顯示屬性。 我使用正確觸發的mvvm模式為按鈕設置了command屬性。
我的問題是,當按下按鈕時,它也無法獲取所選項目,我猜它還沒有觸發selectedItem事件。
按下按鈕時是否可以強制此事件?
<Button
Height="20"
Width="20"
Grid.Column="3"
Grid.Row="0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RemoveClick}"
CommandParameter="{Binding SelectedItem, ElementName=serverListView, Mode=TwoWay}">
您可以:-將命令的commandParameter設置為{Binding}-將SelectedItem綁定到VM的某些屬性-在命令執行方法開始時將此屬性設置為command參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.