2014-09-23 120 views
0

我已經綁定了一個圖像在一個列表框中,當我點擊一個綁定圖像時,將根據源圖像設置綁定圖像資源。如何通過點擊綁定圖像從另一個綁定圖像源路徑獲取圖像源路徑

這是我想從綁定數據中顯示圖像的代碼。

<Grid x:Name="Icon" Margin="134,51,173,556">   
    <Image x:Name="MyIconImage" HorizontalAlignment="Left" Height="90" Width="93" Source="" /> 
</Grid> 

下面是代碼,我已經綁定數據

<Grid Margin="0,366,0,0"> 
    <ListBox x:Name="List" 
       ItemsSource="{Binding ListItemSource}"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <Image x:Name="IconListImage" Source="{Binding IconPath}" Width="48" Height="48" Tap="IconListImage_Tap"/> 
        <TextBlock x:Name="appName" Text="{Binding AppName}"/> 
        <TextBlock Text="{Binding IconPath}"/> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</Grid> 

回答

0

你嘗試SelectedValuePath?

<Image x:Name="MyIconImage" HorizontalAlignment="Left" Height="90" Width="93" Source="{Binding ElementName=List, Path=SelectedValue}" /> 

<ListBox x:Name="List" ItemsSource="{Binding ListItemSource}" SelectedValuePath="IconPath"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <Image x:Name="IconListImage" Source="{Binding IconPath}" Width="48" Height="48" Tap="IconListImage_Tap"/> 
       <TextBlock x:Name="appName" Text="{Binding AppName}"/> 
       <TextBlock Text="{Binding IconPath}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

是的我試過了,但沒有工作.. – 2014-09-25 05:10:49