[英]Data binding part of string in XAML
I'm trying to achieve the following 我正在努力实现以下目标
<controls:Carousel.ItemTemplate>
<DataTemplate>
<Image Width="200"
Height="200"
VerticalAlignment="Center"
Source="/Assets/DemoImages/123_DemoImage.jpg"
Stretch="Uniform" />
</DataTemplate>
</controls:Carousel.ItemTemplate>
Given the itemsource of 给定的项目来源
<controls:Carousel x:Name="CarouselControl" ItemsSource="{x:Bind PropertySearchList}"
and PropertySearchList is a 而PropertySearchList是一个
List<ToLetProperty> PropertySearchList
with the ToLetProperty class having a string property of FrontImage (and other properties) 与ToLetProperty类具有FrontImage的字符串属性(和其他属性)
for example : 例如 :
Source="/Assets/DemoImages/{ToLetProperty.FrontImage}"
When we use {x:Bind}
with data templates, we must indicate the type being bound to by setting an x:DataType
value. 当我们将
{x:Bind}
与数据模板一起使用时,必须通过设置x:DataType
值来指示要绑定的x:DataType
。 We can set the base class type to it. 我们可以为其设置基类类型。
In the Image
control, we can use set FrontImage
property to the Source by the x:Bind
. 在
Image
控件中,可以通过x:Bind
将FrontImage
属性设置为Source。
For example: 例如:
<controls:Carousel x:Name="CarouselControl" ItemsSource="{x:Bind PropertySearchList}" >
<controls:Carousel.ItemTemplate>
<DataTemplate x:DataType="local:ToLetProperty">
<Image Width="200" Height="200" VerticalAlignment="Center" Source="{x:Bind FrontImage}" Stretch="Uniform" />
</DataTemplate>
</controls:Carousel.ItemTemplate>
</controls:Carousel>
By the way, I suggest you use the ObservableCollection
to instead of List
. 顺便说一句,我建议您使用
ObservableCollection
代替List
。 It represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed. 它表示一个动态数据集合,当添加,删除或刷新整个列表时会提供通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.