【发布时间】:2017-06-27 13:42:47
【问题描述】:
这是我的 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>
我的视图模型:
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) });
我尝试对 URL 进行编码,甚至使用本地图像。图像只是没有显示在 ViewCell 列表中。甚至没有错误。我做错了吗?
【问题讨论】:
-
除了图片加载是否正确?
-
需要您的页面的 xaml,其中定义了 viewcell 的列表并编码您如何在页面上设置绑定
-
VisualStudio 的
Output窗口在构建/启动时出现任何错误?即那里显示的任何 BindingErrors ? -
除图像外一切正常。
标签: c# xamarin.forms