![](/img/trans.png)
[英]ComboBox binding inside Item template with IEnumerable collection
[英]How to get the Binding element of a collection inside an item template in WPF?
我有一个自定义控件RadCoverFlow,它将Image的集合作为itemsSource。
<StackPanel Orientation="Vertical" Background="Black">
<telerik:RadCoverFlow x:Name="coverFlow"
ItemsSource="{Binding ViewImages, Mode=OneWay}"
ItemTemplate="{StaticResource ImageTemplate}"
</telerik:RadCoverFlow>
</StackPanel>
我想使用数据模板定义图像的宽度,高度和其他几个属性。 我的问题是,在数据模板中,我需要为每个图像指定一个源,但是该源已经在代码中指定了。
<DataTemplate x:Key="ImageTemplate">
<Image Source="" Width="100" Height="100" Stretch="Uniform" telerik:RadCoverFlow.EnableLoadNotification="True" />
</DataTemplate>
我如何不能重新指定源,或像{Binding ViewImages [i]}那样将源绑定到源,在这种情况下我将是什么?
谢谢
理想情况下,您的业务对象和UI应该完全分开,因此ItemsSource
不应包含Image
UI对象
但这就是说,请尝试使用隐式样式设置属性
<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.