2012-02-03 61 views
0

我需要將數據綁定到我的自定義類中的一個元素。我已經通過附加屬性將ItemSource作爲telerik:RadTransitionControl的ObservableCollection。但是,我需要提供圖像成員作爲Image控件的源代碼。我嘗試了以下方法,但未成功。提供圖像控件的源代碼

<Grid Background="Black"> 
     <telerik:RadTransitionControl x:Name="radControl" adRotator:AdRotatorExtensions.ItemChangeDelay="0:0:3" 
             adRotator:AdRotatorExtensions.CurrentSelectedIndex="0" 
             adRotator:AdRotatorExtensions.IndexChanged="{Binding TopItemCommand, Mode=OneWay}" 
             adRotator:AdRotatorExtensions.ItemsSource="{Binding Path=ImagePaths}" 
             VerticalAlignment="Center" 
             HorizontalAlignment="Center" Width="650"> 
      <telerik:RadTransitionControl.Transition> 
       <telerik:MotionBlurredZoomTransition /> 
      </telerik:RadTransitionControl.Transition> 

      <telerik:RadTransitionControl.ContentTemplate> 
       <DataTemplate> 
        <Image Source="{Binding Path=ImagePaths.AdImage}" /> 
       </DataTemplate> 
      </telerik:RadTransitionControl.ContentTemplate> 

     </telerik:RadTransitionControl> 
    </Grid> 
+0

什麼是綁定錯誤?你應該在輸出窗口中看到它們。 – 2012-02-03 17:31:45

+0

什麼都沒有。屏幕只保留空白而不顯示圖像。 – logeeks 2012-02-03 17:34:02

+0

我的意思是visual studio輸出窗口(查看 - >輸出)。當你遇到綁定相關的問題時,你應該經常在那裏查看。它可能會幫你省去一趟旅程。 ;) – 2012-02-03 17:52:35

回答

1

an ImagePaths對象已被設置爲該項目的DataContext。這意味着綁定已經指向(可以這麼說)對象的一個​​實例。所以,當你告訴它綁定在ImagePaths.AdImage它不知道如何找到你正在尋找的財產。好消息是,你所要做的就是提供對象的路徑 - 刪除ImagePaths部分(和點),你應該很好走。

例如...

class something 
{ 
    public string someImage {...} 
} 

<DataTemplate> <!--------- the data context of this item is an instance of 
          my "something" class, so i need to set the path 
          to be the property on the object ---> 

    <Image Source="{Binding Path=someImage}" /> 

</DataTemplate> 

here is a very helpful article on debugging bindings in WPF
更多信息here is an excellent article on MSDN
here is a datatemplate article from Dr. WPF

+0

用下面的語句取代沒有成功 logeeks 2012-02-03 17:51:15

+2

你應該看看調試綁定文章... http:///bea.stollnitz.com/blog/?p=52它會告訴你如何爲綁定添加調試信息 – 2012-02-03 17:53:14