2012-02-03 60 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