We are developing a small cart application using xamarin forms in visual studio 2019. We like to implement horizontal grouping listview in Xamarin forms. I tried flowlistview group but it is not able to bind the header template. is there any custom render available for horizontal grouping listview or give me a solution to resolve this issue
My code: Homepage.xaml
<flv:FlowListView SeparatorVisibility="None"
HasUnevenRows="false" GroupDisplayBinding="{Binding Heading}"
IsGroupingEnabled="True"
FlowItemsSource="{Binding ListOfPeople}">
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Label Text="{Binding DisplayName}" />
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
HomepageViewModel:
private List<PersonList> _listOfPeople;
public List<PersonList> ListOfPeople { get { return _listOfPeople; } set { _listOfPeople = value
public HomePageViewModel()
{
var sList = new PersonList()
{
new Person() { FirstName = "Sally", LastName = "Sampson" },
new Person() { FirstName = "Taylor", LastName = "Swift" },
new Person() { FirstName = "John", LastName = "Smith" }
};
sList.Heading = "S";
var dList = new PersonList()
{
new Person() { FirstName = "Jane", LastName = "Doe" }
};
dList.Heading = "D";
var jList = new PersonList()
{
new Person() { FirstName = "Billy", LastName = "Joel" }
};
jList.Heading = "J";
var list = new List<PersonList>()
{
sList,
dList,
jList
};
ListOfPeople = list;
}
}
Related
I'm trying to seed my database but I am getting this error when its time to assign a role to a user Role SystemAdministrator does not exist. I have an additional field in the AspNetRoles table called VariableName so I can't use the rolemanager to add it.
This is my Seed code
protected override void Seed(ApplicationDbContext context)
{
if (!context.AspNetApplications.Any())
{
context.AspNetApplications.AddOrUpdate(
new AspNetApplications()
{
Id = "abcd-bcda",
Name = "AppnameOne",
Description = "Description",
SecretKey = GenerateSecretKey(),
CreatedOn = DateTime.Now,
UpdatedOn = DateTime.Now
}
);
context.SaveChanges();
}
if (!context.Roles.Any())
{
context.Roles.AddOrUpdate(
new AspNetRoles
{
Id = "93547517-f40d-4479-a7f4-73e86d3edddd",
Name = "System Administrator",
VariableName = "SystemAdministrator",
ApplicationId = "abcd-bcda"
});
context.SaveChanges();
}
if (!context.Users.Any())
{
var userStore = new UserStore<ApplicationUser>(context);
var userManager = new UserManager<ApplicationUser>(userStore);
var user = new ApplicationUser
{
Id = "bbccdd-ccbbdd",
Email = "system#appnameone.com",
UserName = "system#appnameone.com",
PhoneNumber = "1234567890"
};
userManager.Create(user,"TestP#ssW0RD");
var userExtended = new AspNetUsersExtendedDetails
{
FirstName = "System",
LastName = "Administrator",
DateOfBirth = DateTime.Now,
UserId = "abcd-bcda"
};
context.AspNetUsersExtendedDetails.AddOrUpdate(userExtended);
userManager.AddToRole("bbccdd-ccbbdd", "SystemAdministrator");
context.SaveChanges();
}
}
Hope someone can take a look at this and let me know where I've gone wrong?
Thank you.
I have a xaml file where I put the picker in and a code behind to populate it. The code used below:
Dictionary<string, int> list = new Dictionary<string, int>
{
{ "Aqua", 6},
{ "Red", 1 },
{ "Silver", 2 },
{ "Teal", 3 },
{ "White", 4 },
{ "Yellow", 55 }
};
foreach (string item in list.Keys)
{
ddlPurpose.Items.Add(item);
}
I am trying to get the value 55 when I select yellow but the only thing I get is 5. I am using this to get the selected value
var val1 = ddlPurpose.SelectedItem.ToString();
var val2 = ddlPurpose.SelectedIndex;
Is it even possible to get the key value? Have looked into the BindablePicker but that didn't seem to work at all. Any help on this is greatly appreciated.
I guess what you meant to do is:
var pSelectedIndex = ddlPurpose.SelectedIndex;
var selectedKey = list.Values.ElementAt(pSelectedIndex);
I would recommend to get familiar with MVVM and in this specific case with Behaviors. I wrote a small example to demonstrate how it may look using MVVM:
public class PickerKeyValueTestViewModel : INotifyPropertyChanged
{
static Dictionary<string, int> colors { get; } = new Dictionary<string, int>
{
{ "Aqua", 6 },
{ "Red", 1 },
{ "Silver", 2 },
{ "Teal", 3 },
{ "White", 4 },
{ "Yellow", 55 }
};
public List<string> Colors { get; } = colors.Keys.ToList();
public string SelectedColor { get; set; }
public void OnSelectedColorChanged()
{
if (string.IsNullOrEmpty(SelectedColor)) return;
var selectedValue = colors[SelectedColor];
}
// Using PropertyChanged.Fody
public event PropertyChangedEventHandler PropertyChanged;
}
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PickerKeyValueTest"
x:Class="PickerKeyValueTest.PickerKeyValueTestPage">
<ContentPage.BindingContext>
<local:PickerKeyValueTestViewModel />
</ContentPage.BindingContext>
<StackLayout
Margin="25">
<Picker
ItemsSource="{Binding Colors}"
SelectedItem="{Binding SelectedColor}">
</Picker>
</StackLayout>
</ContentPage>
im trying to add my contacts in telegram-cli by using vcard. but when i use this command:
import_card <card>
nothing happen! it just goes to next line without any error and no contact added.
my vcard is VERSION:2.1
how can i improt my contacts to my telegram account by using vcard?
Install-Package TLSharp
client = new TelegramClient(apiId, apiHash);
await client.ConnectAsync();
var phoneContact = new TLInputPhoneContact() { phone = "", first_name = "", last_name = "" };
var contacts = new List<TLInputPhoneContact>() { phoneContact };
var req = new TeleSharp.TL.Contacts.TLRequestImportContacts() { contacts = new TLVector<TLInputPhoneContact>() { lists = contacts } };
var rrr= await client.SendRequestAsync<TeleSharp.TL.Contacts.TLImportedContacts>(req);
private async Task<bool> ImportContact(string _phone , string _first_name , string _last_name)
{
//https://github.com/sochix/TLSharp/issues/243
var phoneContact = new TLInputPhoneContact() { phone = _phone, first_name = _first_name, last_name = _last_name };
var contacts = new List<TLInputPhoneContact>() { phoneContact };
var req = new TLRequestImportContacts() { contacts = new TLVector<TLInputPhoneContact>() { lists = contacts } };
TLImportedContacts result = await client.SendRequestAsync<TLImportedContacts>(req);
if (result.users.lists.Count > 0)
return true;
else return false;
}
For some reason, the 'UserManager' of 'Identity' does not store a new user when using inside my seeding class. Everything else in the seeding class works fine as expected, it is just that 'CreateAsync' method issue. Here is the code:
public class WorldContextSeedData
{
private WorldContext _context;
private UserManager<WorldUser> _userManager;
public WorldContextSeedData(WorldContext context, UserManager<WorldUser> userManager)
{
_context = context;
_userManager = userManager;
}
public async Task EnsureSeedData()
{
if (await _userManager.FindByEmailAsync("lucas#test.com") == null)
{
//add user
var newUser = new WorldUser
{
UserName = "Lucas",
Email = "lucas#test.com"
};
await _userManager.CreateAsync(newUser, "MyP#ssword!");
}
if (!_context.Trips.Any())
{
//Add new Data
var usTrip = new Trip()
{
Name = "US Trip",
CreatedBy = "Lucas",
Timestamp = DateTime.Now,
Stops = new List<Stop>()
{
new Stop { Name= "Atlanta, GA", Order = 0},
new Stop { Name= "NYC, NY", Order = 1},
new Stop { Name= "Tempe, AZ", Order = 2}
}
};
var worldTrip = new Trip()
{
Name = "World Trip",
CreatedBy = "Lucas",
Timestamp = DateTime.Now,
Stops = new List<Stop>()
{
new Stop { Name= "Poland", Order = 0},
new Stop { Name= "France", Order = 1},
new Stop { Name= "Germany", Order = 2}
}
};
_context.Trips.Add(usTrip);
_context.Stops.AddRange(usTrip.Stops);
_context.Trips.Add(worldTrip);
_context.Stops.AddRange(worldTrip.Stops);
_context.SaveChanges();
}
}
}
As per Steve's great comment tip, I was able to verify that the password was too weak. Once I made the password stronger (digit was required), the issue was resolved.
Here, I have introduced a variable that would contain returned result of creating a new user:
IdentityResult result = await _userManager.CreateAsync(newUser, newUserPassword);
You can Use
IdentityResult result = await _userManager.CreateAsync(newUser, "MyP#ssword!");
to see what is the problem in result.
IdentityResult contains bool Succeeded for determine how the create going on. and contains Errors Property to show you what goes wrong.
add these line of codes to IdentityHostingStartup.cs:
services.Configure<IdentityOptions>(x => {
x.Password.RequireDigit = false;
x.Password.RequiredLength = 2;
x.Password.RequireUppercase = false;
x.Password.RequireLowercase = false;
x.Password.RequireNonAlphanumeric = false;
x.Password.RequiredUniqueChars = 0;
x.Lockout.AllowedForNewUsers = true;
x.Lockout.MaxFailedAccessAttempts = 5;
x.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromSeconds(30);
});
I am learning MVC 4 razor,i am trying to get display member and value from drop down list but i am not able to get it, this is my code
<script src="~/Scripts/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).change(function ()
{
var selectedItem = $("#Employee :selected").text();
var selectedValue = $("#Employee").val();
alert(selectedItem+" "+selectedValue);
//document.getElementById("#lblEmployee").innerText = selectedItem;
});
</script>
#Html.DropDownList("Employee", ViewData["lstEmp"] as SelectList)
please help me out,If any other way rather using JQuery please tell.
Controller:
public ActionResult Create()
{
var VM = new ProjectViewModel();
int projectId = 0;
var list = new List<SelectListItem>();
list.Add(new SelectListItem { Value = "1", Text = "a" });
list.Add(new SelectListItem { Value = "2", Text = "b" });
list.Add(new SelectListItem { Value = "3", Text = "c" });
VM.ddlClientLists = list
return View("Create",VM);
}
view model:
public class VM
{
public List<SelectListItem> ddlClientLists { set; get; }
public VM(){
ddlClientLists = new List<SelectListItem>();
}
}
in create view:
#model project.Models.VM
#Html.DropDownList("ddlclientLists", Model.ddlClientLists, "select")