[英]Datagrid get hidden cell from sellected row
Hi i have problem with accessing hidden value in DataGrid
of selected Row
: 嗨,我在访问选定Row
DataGrid
的隐藏值时DataGrid
问题:
<DataGrid Name="grid" ItemsSource ="{Binding}" IsReadOnly="True" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Id_user" Binding="{Binding id_user}" Visibility="Hidden"/>
<DataGridTextColumn Header="A" Binding="{Binding A}" />
<DataGridTextColumn Header="B" Binding="{Binding B}" />
</DataGrid.Columns>
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseDoubleClick" Handler="selectRow"/>
</Style>
</DataGrid.ItemContainerStyle>
</DataGrid>
This is code witch I use to do that, but I got that element doesnt exist. 这是我用来做的代码女巫,但我知道该元素不存在。
private void selectRow(object sender, RoutedEventArgs e)
{
DataRowView row = (DataRowView)grid.SelectedItems[0];
var x = row["Id_user"];
this.NavigationService.Navigate(new PageA((string)x));
}
Is there a simply way to do that? 有没有简单的方法可以做到这一点?
EDIT: 编辑:
row["ID"]
is not SelectedItem.id
. row["ID"]
不是SelectedItem.id
。 This is diffrent value . 这是不同的值 。
You should move this logic to viewmodel. 您应该将此逻辑移至viewmodel。 Event handler in code behind should look like this: 后面代码中的事件处理程序应如下所示:
private void selectRow(object sender,RoutedEventArgs e)
{
ViewModel.Navigate();
}
And here is Navigate()
implemetation: 这是Navigate()
实现:
public void Navigate()
{
NavigationService.Navigate(new PageA(SelectedItem.id_user));
}
All thats left to do is to bind SelectedItem
property on view model to your DataGrid
剩下要做的就是将视图模型上的SelectedItem
属性绑定到您的DataGrid
<DataGrid Name="grid" SelectedItem="{Binding SelectedItem}" ItemsSource ="{Binding Collection}" IsReadOnly="True" AutoGenerateColumns="False" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.