简体   繁体   English

如何在WPF的项目模板中获取集合的Binding元素?

[英]How to get the Binding element of a collection inside an item template in WPF?

I have a custom control RadCoverFlow that takes a collection of Image as an itemsSource. 我有一个自定义控件RadCoverFlow,它将Image的集合作为itemsSource。

<StackPanel Orientation="Vertical" Background="Black">
    <telerik:RadCoverFlow x:Name="coverFlow"
                          ItemsSource="{Binding ViewImages, Mode=OneWay}"
                          ItemTemplate="{StaticResource ImageTemplate}"
    </telerik:RadCoverFlow>
</StackPanel>

I want to define the widh, the height and a couple of other properties of the Images using a data template. 我想使用数据模板定义图像的宽度,高度和其他几个属性。 My problem is that in the Data Template, I need to specify a source for each images, but that source is already specified in code. 我的问题是,在数据模板中,我需要为每个图像指定一个源,但是该源已经在代码中指定了。

    <DataTemplate x:Key="ImageTemplate">
        <Image Source="" Width="100" Height="100" Stretch="Uniform" telerik:RadCoverFlow.EnableLoadNotification="True" />
    </DataTemplate>

How can I not re-specify the Source, or bind the source to the Source like {Binding ViewImages[i]}, what would be i in this case? 我如何不能重新指定源,或像{Binding ViewImages [i]}那样将源绑定到源,在这种情况下我将是什么?

Thank You 谢谢

Ideally, your business objects and your UI should be completely separate, so your ItemsSource should not have Image UI objects 理想情况下,您的业务对象和UI应该完全分开,因此ItemsSource不应包含Image UI对象

But that said, try and use an implicit style to set your properties 但这就是说,请尝试使用隐式样式设置属性

<telerik:RadCoverFlow.Resources>
    <Style TargetType="{x:Type Image}">
        <Setter Property="Height" Value="100" />
        <Setter Property="Width" Value="100" />
        <Setter Property="Stretch" Value="Uniform" />
        <Setter Property="telerik:RadCoverFlow.EnableLoadNotification" Value="True" />
    </Style>
</telerik:RadCoverFlow.Resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM