2016-06-12 44 views
1

我想從ListView中獲取用作ObservableCollection的對象中的所有數據。 ListView正在正常工作我想在項目被選中時在TextBlockListView之外)的信息中用信息更新該對象。SelectedItem更改文本塊變量

我該怎麼辦呢?我做錯了什麼?

所以到代碼:

<ListView 
    x:Name="dataGrid" 
    ItemsSource="{Binding Friends}" 
    Height="586" 
    BorderThickness="0" 
    SelectedItem="{Binding SelectedItemFriends,Mode=TwoWay}" 
    HorizontalAlignment="Left" Width="460"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <StackPanel Orientation="Horizontal"> 
      <Image Source="Resources\Images\ic_status.png" Height="24" Width="18"/> 
      <StackPanel Margin="5" Orientation="Vertical"> 
       <TextBlock FontWeight="Bold" Text="{Binding name}"/> 
       <StackPanel x:Name="RemoveItems" Margin="5" Orientation="Vertical"> 
        <TextBlock Text="{Binding lastLocation, StringFormat='Location: {0}'}"/> 
        <TextBlock Text="{Binding timestamp}"/> 
       </StackPanel> 
      </StackPanel> 
     </StackPanel> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
<StackPanel x:Name="AdditionItems" Margin="5" Orientation="Vertical" Visibility="Visible"> 
    <TextBlock> 
     <TextBlock.Text> 
     <MultiBinding Converter="{StaticResource myConverter}"> 
      <Binding ElementName="dataGrid" Path="loc.country"/> 
      <Binding ElementName="dataGrid" Path="loc.area"/> 
     </MultiBinding> 
     </TextBlock.Text> 
    </TextBlock> 
</StackPanel> 

回答

2

你應該在你的綁定指定SelectedItem屬性:

<TextBlock> 
     <TextBlock.Text> 
     <MultiBinding Converter="{StaticResource myConverter}"> 
      <Binding ElementName="dataGrid" Path="SelectedItem.loc.country"/> 
      <Binding ElementName="dataGrid" Path="SelectedItem.loc.area"/> 
     </MultiBinding> 
     </TextBlock.Text> 
    </TextBlock> 
+0

它的工作。真棒。謝謝你的時間 :) – Ricardo