这是我的xaml绑定:
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dataTemplateSelector="clr-namespace:VaultixForm;assembly=VaultixForm"
x:Class="VaultixForm.CustomCells.OutgoingViewCell">
<Grid ColumnSpacing="2" Padding="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="0"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Frame Grid.Row="0" OutlineColor="Transparent" HasShadow="False" Grid.Column="1" BackgroundColor="#F5F5F5">
<Image Aspect="AspectFill" x:Name="ImageView" Source="{Binding ImageURL}"/>
<Label x:Name="TextView" TextColor="Black" Text="{Binding Text}" />
</Frame>
<Label Grid.Row="1" FontSize="Micro" Grid.Column="1" HorizontalTextAlignment="End" Text="{Binding MessagDateTime, StringFormat='{0:MM/dd/yyyy hh:mm tt}'}" TextColor="Gray"></Label>
</Grid>
我的ViewModel:
private string text;
public string Text
{
get { return text; }
set { text = value; RaisePropertyChanged(); }
}
private string imageurl;
public string ImageURL
{
get { return imageurl; }
set { imageurl = value; RaisePropertyChanged(); }
}
private DateTime messageDateTime;
public DateTime MessagDateTime
{
get { return messageDateTime; }
set { messageDateTime = value; RaisePropertyChanged(); }
}
private bool isIncoming;
public bool IsIncoming
{
get { return isIncoming; }
set { isIncoming = value; RaisePropertyChanged();}
}
public bool HasAttachement => !string.IsNullOrEmpty(attachementUrl);
private string attachementUrl;
public string AttachementUrl
{
get { return attachementUrl; }
set { attachementUrl = value; RaisePropertyChanged();}
}
}
}
添加数据就像这样
Messages.Add(new MessageViewModel { ImageURL = "https://beebom-redkapmedia.netdna-ssl.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg", IsIncoming = false, MessagDateTime = DateTime.Now.AddMinutes(-25) });
我尝试对网址进行编码,甚至使用本地图片。图像仅显示在ViewCell列表中。甚至没有错误。我做错了吗?
答案 0 :(得分:0)
您绑定到ImageUrl
,但您的媒体资源名为ImageURL
。请记住,WPF(一般来说)案例敏感:
XAML通常说区分大小写。出于解决支持类型的目的,WPF XAML区分大小写与CLR区分大小写的规则相同。当按名称与程序集中的基础类型或类型成员进行比较时,必须使用敏感框来指定对象元素,属性元素和属性名称 >。 XAML语言关键字和基元也区分大小写。值并不总是区分大小写。值的区分大小写取决于与获取值的属性关联的类型转换器行为,或属性值类型。例如,采用Boolean类型的属性可以采用true或True作为等效值,但仅仅因为字符串到布尔值的本机WPF XAML解析器类型转换已经允许这些作为等价物。