[英]DataGrid ItemSource bound to selected item within another DataGrid
我有以下數據結構:
List<Customer> currentCustomers {...}
public class Customer
{
public string ID { get, set }
public string Name { get, set }
[...]
public List<Products> { get, set }
}
我有一個綁定到currentCustomers
列表的客戶DataGrid。 我想做的是將第二個DataGrid綁定到客戶中的所選項目,以顯示該客戶的所有產品信息。
即,用戶單擊“客戶”數據網格內的“客戶”,然后根據該“客戶產品”自動更新第二個DataGrid。
這有可能嗎?
如果是這樣,周圍是否有資源可以告訴/告訴我如何進行?
這應該工作:
<DataGrid x:Name="one"></DataGrid>
<DataGrid x:Name="two" DataContext="{Binding ElementName=one, Path=SelectedItem.Products}"></DataGrid>
只需將其綁定到SelectedItem屬性:
<DataGrid x:Name="customersList" CanSelectMultipleItems="false" ... />
<DataGrid x:Name="customerDetails"
ItemsSource = "{Binding ElementName = customersList,
Path = SelectedItem.Products}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.