2009-04-15 13 views
2

私は、ItemTemplateListBoxといくつかのデータバインディング(Imageを含む)を持っています。WPF Image Source Binding

ItemsSourceがコードビハインドに設定されています。画像ソースにバインドされているオブジェクトのメンバーを更新することによって、画像のソースを変更しようとするまで、すべてが期待どおりに機能します。私は間違って何をしていますか?ここで

はXAMLです:

<ListBox x:Name="myList" MouseDoubleClick="myList_MouseDoubleClick" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Vertical" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Border BorderBrush="DarkGray" BorderThickness="1"> 
       <StackPanel Orientation="Horizontal" Width="100"> 
        <Image Width="38" Height="38" Source="{Binding Path=icon}" /> 
        <StackPanel Width="100"> 
         <Label Content="{Binding Path=name}" /> 
         <Label Content="{Binding Path=state}" /> 
        </StackPanel> 
       </StackPanel> 
      </Border> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

分離コードのいくつかの部分:

Window_Initializedで:

myList_MouseDoubleClick
myList.ItemsSource = myLineList; 

Line aLine = myList.SelectedItem as Line; 
if (aLine != null) { 
    aLine.icon = "idle.jpg"; 
} 

答えて

1

ドゥあなたの "Line"クラスはINotifyPropertyChangedを実装するか、または依存関係プロパティを使用しますか?これは、 "icon"プロパティの値が変更されたことをバインディングに通知する何らかの方法を持たなければなりません。

+0

ありがとうございました。 mfcから来て、またadobeのフラッシュをコード化して私は当然これを取った... –