Hi, i hope someone could answere/help me. I've created a View which displays a button and a label. Also a Listview is beneth those two elements on the view.
The labeltext and the listview shows userdate which gets from databinding of a viewmodel. A addet on every list-entry also a button, which does directly the same Icommand like the button which is directly above the listview. The Icommand sets a string (username) into the device credentials (Xam.Plugins.Settings) and also does a OnPropertyChanged which updates the labeltext on the view.
It works 100% perfectly while using this one button directly on the view, but the buttons in the listview just ignore the Propertychange. The other code in the Icommand is also executed - i am just talking about the process of updating this labeltext with propertychange.
anyone 've an idea?
View.XAML
<StackLayout Padding="30,20,30,0">
// ******This is the Button which can do the Propertychange!
<Image x:Name="test" Source="icologin_50.png" VerticalOptions="Start" HorizontalOptions="Start">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" CommandParameter="manu" />
</Image.GestureRecognizers>
</Image>
//******This is the Label, which i want to be updated with propertychange
<Label x:Name="LabelChange" x:FieldModifier="Public" Text="{Binding UserWhichIsLoggedIn}" VerticalOptions="Start" HorizontalOptions="CenterAndExpand" TextColor="White" FontSize="50" />
// ******This is the Lisview
<ListView x:Name="Userlist" Margin="20" RowHeight="60" BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="20,0,20,0" Orientation="Horizontal" >
<Label Text="{Binding Firstname}" VerticalTextAlignment="Center" FontSize="20" TextColor="#033a63"/>
<Label Text="{Binding Lastname}" VerticalTextAlignment="Center" FontSize="20" TextColor="#033a63"/>
<Image x:Name="SwitchUserIcon" Source="icologin_50.png" HorizontalOptions="EndAndExpand">
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding TapCommand}"
CommandParameter="{Binding Uid}"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
View.XAML.CS
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Userchange : ContentPage
{
public Userchange()
{
InitializeComponent();
BindingContext = new UserSimpleViewModel();
}
protected override void OnAppearing()
{
base.OnAppearing();
Device.BeginInvokeOnMainThread(async () =>
{
UserSimpleViewModel Client_UserSimpleViewModel = new UserSimpleViewModel();
Infotext.IsVisible = true;
Userlist.ItemsSource = await Client_UserSimpleViewModel.Userlisteladen();
});
}
}
ViewModel
public class UserSimpleViewModel : INotifyPropertyChanged
{
UserSimple Model_UserSimple = new UserSimple();
RestClient client_RestClient = new RestClient();
LoginEngine client_LoginEngine = new LoginEngine();
ICommand tapCommand;
public string Firstname { get; set; }
public string Lastname { get; set; }
public int Uid { get; set; }
public UserSimpleViewModel()
{
tapCommand = new Command(OnTapped);
}
public string UserWhichIsLoggedIn
{
set
{
Model_UserSimple._userwhichisloggedin = Bonisda.Helpers.Settings.LoginUsername;
}
get
{
Model_UserSimple._userwhichisloggedin = Bonisda.Helpers.Settings.LoginUsername;
return Model_UserSimple._userwhichisloggedin;
}
}
public ICommand TapCommand
{
get { return tapCommand; }
}
public async Task<List<UserSimpleViewModel>> Userlisteladen()
{
return await client_RestClient.GetAllUserSimple("URL");
}
public void OnTapped(object s)
{
string entered_password = null;
entered_password = s.ToString();
Bonisda.Helpers.Settings.LoginUsername = entered_password;
Model_UserSimple._userwhichisloggedin = Bonisda.Helpers.Settings.LoginUsername;
OnPropertyChanged("UserWhichIsLoggedIn");
//PropertyChanged(this, new PropertyChangedEventArgs("UserWhichIsLoggedIn")); // its also not working with this one
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}