0

したがって、最初の列 (TestID) で関連付けられた 2 つのリスト ビューがあります。最初のリストビューで行を選択すると、2番目のリストビューで行が自動的に選択されるようにします。これは私がこれまでに持っているものです。

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

2番目の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 に答える