0

所以我有两个与第一列(TestID)相关的列表视图。当我在第一个列表视图中选择行时,我希望在第二个列表视图中自动选择该行。这就是我到目前为止所拥有的。

AutomationTestResults tr = new AutomationTestResults();
    public int SelectedTestID
    {

        get
        {

            return tr.TestID;
        }

        set
        {
            tr.TestID = value;
            NotifyPropertyChanged("SelectedTestID");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void NotifyPropertyChanged(String propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

=============XAML===================================== =====================

<ListView ItemsSource="{Binding TRCollection }" SelectedItem="{Binding SelectedTestID}" SelectionChanged="ListView_SelectionChanged"
                  Grid.Row="1" Height="197" HorizontalAlignment="Left" Margin="12,22,0,0" Name="listView1" VerticalAlignment="Top" Width="680">
        </ListView>
        <ListView ItemsSource="{Binding TCCollection}" SelectedItem="{Binding SelectedTestID}" SelectionChanged="ListView_SelectionChanged"
                  Grid.Row="1" Height="245" HorizontalAlignment="Left" Margin="12,251,0,0" Name="listView2" VerticalAlignment="Top" Width="680" >
4

2 回答 2

1

如果您需要做的就是在第二个 ListView 中选择相应的行,您可以像这样绑定“SelectedIndex”属性

<ListView ItemsSource="{Binding TRCollection }" SelectedItem="{Binding SelectedTestID}" SelectionChanged="ListView_SelectionChanged"
          Grid.Row="1" Height="197" HorizontalAlignment="Left" Margin="12,22,0,0" Name="listView1" VerticalAlignment="Top" Width="680"/>

<ListView ItemsSource="{Binding TCCollection}" SelectedIndex="{Binding Path=SelectedIndex, ElementName=listView1}" SelectedItem="{Binding SelectedTestID}" SelectionChanged="ListView_SelectionChanged"
          Grid.Row="1" Height="245" HorizontalAlignment="Left" Margin="12,251,0,0" Name="listView2" VerticalAlignment="Top" Width="680" />
于 2013-04-24T18:00:33.880 回答
0

为什么不只是

<ListView x:Name="listView1"/> <!-- etc.. -->

<ListView SelectedItem="{Binding SelectedItem, ElementName=listView1}"/> 
于 2013-04-24T18:00:14.140 回答