![](/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.