Xamarin表单ListView图像绑定 [英] xamarin form listview image binding
本文介绍了Xamarin表单ListView图像绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果将项目添加到列表视图中,则会添加项目,但不会显示图像.我必须重新启动应用程序才能查看它.
If I add an item to a listview, the items is added but the image is not showed. I have to restart application to view it.
该项目已正确添加,但是图像不可见.
The Item is correctly added but the image is not visible.
此处是CS.
ObservableCollection<Libreria> items = new ObservableCollection<Libreria>(new Libreria().GetLibrerie());
public Home()
{
InitializeComponent ();
lstLibrerie.ItemsSource = items;
//pickerLibrerie.ItemsSource = new Libreria().GetLibrerie();
}
public void Reload(Libreria newLib)
{
items.Insert(0, newLib);
}
这里是xaml
<ListView x:Name="lstLibrerie" RowHeight="120">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ScrollView> <!-- left, top, right, bottom -->
<StackLayout Margin="0,20,0,0" Orientation="Horizontal">
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Margin="20,0,0,0" Source="{Binding Icona}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Aspect="AspectFit" HeightRequest="120"></Image>
<Label Text="{Binding Label}" Grid.Column="1" Grid.Row="0" FontAttributes="Bold" />
<Label Text="{Binding DataUltimaApertura}" Grid.Column="1" Grid.Row="1" />
<Label Text="{Binding EtichettaNrOggetti}" Grid.Column="1" Grid.Row="2" />
<BoxView HeightRequest="1" Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand" Color="Black" />
</Grid>
</StackLayout>
</ScrollView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
能帮帮我吗?预先感谢
推荐答案
public class Libreria : INotifyPropertyChanged
{
[PrimaryKey]
public Guid Id { get; set; }
public Tipo Tipo { get; set; }
public int IdTipo { get; set; }
public int NrOggetti { get; set; }
public string DataUltimaApertura { get; set; }
string _label;
string _icon;
public Libreria()
{
}
public string Label
{
set
{
if (_label != value)
{
_label = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Label"));
}
}
}
get
{
return _label;
}
}
public string Icona
{
set
{
if (_icon != value)
{
_icon = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Icona"));
}
}
}
get
{
return _icon;
}
}
public string EtichettaNrOggetti
{
get
{
return string.Format("Nr. elementi: {0}", NrOggetti);
}
}
public List<Libreria> GetLibrerie()
{
string query = string.Format("SELECT COUNT(oggetto.idlibreria) AS NrOggetti, Label, IdTipo, DataUltimaApertura, Icona FROM libreria LEFT JOIN oggetto ON libreria.id = oggetto.idlibreria GROUP BY libreria.id ORDER BY dataultimaapertura DESC");
return App.DBConnection.Query<Libreria>(query);
// return App.DBConnection.Table<Libreria>().OrderByDescending(lib => lib.Dataultimaapertura).ToList();
}
public Guid Insert()
{
this.Id = Guid.NewGuid();
string query = string.Format("INSERT INTO libreria(id, idtipo, label, dataultimaapertura, icona) VALUES('" + this.Id + "'," + this.IdTipo + ",'" + this.Label + "', '" + this.DataUltimaApertura + "', '" + this.Icona + "')");
App.DBConnection.Execute(query);
return this.Id;
}
public event PropertyChangedEventHandler PropertyChanged;
}
这篇关于Xamarin表单ListView图像绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文