My first question here.
Here is the deal:
I'm trying to settle a Listview that would bring me all the names of some businesses registered in one event.
The codes are bellow:
First I creatted a Model
public class BusinessReg
{
public int Id { get; set; }
public String BusinessName { get; set; }
public String BusinessFantasyName { get; set; }
public String BusinessArea { get; set; }
public String BusinessSpecificArea { get; set; }
public String Country { get; set; }
public String State { get; set; }
public String City { get; set; }
public String Adress { get; set; }
public String Neighbourhood { get; set; }
public String Number { get; set; }
public String Complement { get; set; }
public Double Latitude { get; set; }
public Double Longitude { get; set; }
public String DateOfReg { get; set; }
public String DateOfMod { get; set; }
public String BusinessStatus { get; set; }
public String RegisteredBy { get; set; }
}
Than I creatted another Class called Services
public class BusinessRegServices
{
public List<BusinessReg> GetBusinessReg()
{
var list = new List<BusinessReg>
{
new BusinessReg
{
BusinessName = "Casadafarofa",
BusinessFantasyName = "casa da farofa2",
BusinessArea ="restaurante",
BusinessSpecificArea = "Casas de Farofaria",
Country ="brazil",
State = "RS",
City = "Rio Grande",
Adress = "avenida Rio Grande",
Neighbourhood = "Cassino",
Number= "1420",
Complement ="",
Latitude = 23,
Longitude = 25,
DateOfReg ="23/09/1984",
DateOfMod ="27/12/1986",
BusinessStatus ="Ativo",
RegisteredBy = "Zé das couves"
},
new BusinessReg
{
BusinessName = "Casadafarofa3",
BusinessFantasyName = "casa da farofa4",
BusinessArea ="restaurante2",
BusinessSpecificArea = "Casas de Farofaria2",
Country ="brazil2",
State = "RS2",
City = "Rio Grande2",
Adress = "avenida Rio Grande2",
Neighbourhood = "Cassino2",
Number= "14202",
Complement ="2",
Latitude = 23.1,
Longitude =25,
DateOfReg ="23/09/1984",
DateOfMod ="27/12/1986",
BusinessStatus ="Ativo",
RegisteredBy = "Zé das couves"
}
};
return list;
}
}
And than I Created a View Class as bellow
public class BusinessRegView
{
public List<BusinessReg> BusinessRegList { get; set; }
public BusinessRegView()
{
var businessRegServices = new BusinessRegServices();
BusinessRegList = businessRegServices.GetBusinessReg();
}
};
On my Mainpage (C# only) I'm trying to list the two business names, but It comes blank page.
public class Config : ContentPage
{
public Config ()
{
BindingContext = new BusinessRegView();
ListView Lista = new ListView
{
ItemsSource = "{Binding BusinessName}"
};
new ScrollView
{
Orientation = ScrollOrientation.Vertical,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Content = Lista,
},
Could anyone help me What I'm doing wrong?
Thanks for all.
Daniel.
The problem is
ItemsSource = "{Binding BusinessName}"
You can use the {Binding ...} notation in a XAML file but not in Code. Here you have to set the ItemsSource to your Collection like:
ItemsSource = businessRegServices.GetBusinessReg();
Or something like this...
You also need to define an item template, otherwise you will see only empty entries...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.