Tôi có một danh sách (xem bên dưới) có trong cửa sổ. Cửa sổ DataContext
có hai thuộc tính, Items
và AllowItemCommand
.WPF Databinding: Làm thế nào để truy cập bối cảnh dữ liệu "cha mẹ"?
Làm cách nào để nhận được ràng buộc cho thuộc tính'Command
cần phải giải quyết chống lại cửa sổ DataContext
?
<ListView ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridViewColumn Header="Action">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>
<!-- this binding is not working -->
<Hyperlink Command="{Binding AllowItemCommand}"
CommandParameter="{Binding .}">
<TextBlock Text="Allow" />
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Bạn có thể truy cập trình gỡ rối và chuyển đến điểm giao diện người dùng đang được xây dựng không? Nếu vậy bạn có thể vào được biến và cố gắng khoan lên –
Giải pháp đơn giản (cũng hoạt động trong ứng dụng Windows 8 Store/Metro) ở đây: [http://stackoverflow.com/questions/15366609/how-to-access- parent-datacontext-in-window-8-store-apps/15419382 # 15419382] (http://stackoverflow.com/questions/15366609/how-to-access-parents-datacontext-in-window-8-store-apps/15419382 # 15419382) – LMK