1

我有一个带有网格视图的简单列表视图,我正在尝试获取某些列的值。

我的 XAML

<ListView SelectionMode="Single" Margin="10,10,0,0" x:Name="activos" Height="211" VerticalAlignment="Top" HorizontalAlignment="Left" Width="555" SizeChanged="activos_SizeChanged" SelectionChanged="activos_SelectionChanged" IsSynchronizedWithCurrentItem="True">
    <ListView.Resources>
        <ResourceDictionary>
            <Style x:Key="hiddenStyle" TargetType="GridViewColumnHeader">
                <Setter Property="Visibility" Value="Collapsed"/>
            </Style>
            <Style TargetType="{x:Type CheckBox}" x:Key="DataGridCheckBox">
                <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="IsEnabled" Value="False" /> <Setter Property="Margin" Value="11 3" /> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type GridViewColumn}},Path=ActualWidth}" />
            </Style>
        </ResourceDictionary>
    </ListView.Resources>
    <ListView.View>
        <GridView x:Name="act_">
            <GridViewColumn Header="Code" Width="0" DisplayMemberBinding="{Binding coddiag}" HeaderContainerStyle="{StaticResource hiddenStyle}" />
            <GridViewColumn Header="Diagnóstico" Width="400" DisplayMemberBinding="{Binding diag}" />
            <GridViewColumn Header="Princip." Width="50">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Style="{StaticResource DataGridCheckBox}" IsChecked="{Binding princi}" Focusable="False" IsHitTestVisible="False" Name="Complete" IsThreeState="False" BorderBrush="Black" Foreground="Black"></CheckBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Fecha" Width="{x:Static System:Double.NaN}" DisplayMemberBinding="{Binding fecha, StringFormat='dd/MM/yyyy'}" />
        </GridView>
    </ListView.View>
</ListView>

基本上,我要做的是在更改所选行并存储其值时访问 GridViewColumn 代码值。

我认为这会更容易,比如 Grid[Row,Column] 或类似的东西......但经过一些研究,看起来我需要使用其他方法......

4

1 回答 1

1

您可以在视图模型的属性上添加 ListView.SelectedItem 绑定。您的视图模型将从该点开始跟踪选择更改。因此,当所选项目更改时,您会在此属性中获得新值。因此,您可以在视图模型的代码中访问所选项目的任何属性(列值)。

于 2013-07-17T10:34:42.050 回答