Issue
I'm working on Xamarin.Forms Application. I set a Condition in ViewModel Page, and per as change the Label Text & Image Button Visibility through Binding.
But the Problem is that, when I open the Page, screen is empty, but when I refresh the Page, then it shows the text.
Below is the code for xml and .cs pages.
IndexViewModel.cs
public override async Task InitializeAsync(object navigationData)
{
var firstname = await SecureStorage.GetAsync("firstname");
if (firstname == null)
{
var RegisteredUserID = await SecureStorage.GetAsync("RegisteredUserID");
_indexText = "Waiting for Identity to be Issued";
IsQRScannerVisible = false;
}
else
{
_indexText = "Your App is Ready";
IsQRScannerVisible = true;
}
await base.InitializeAsync(navigationData);
}
Bindable Properties
private string _indexText;
public string IndexText
{
get => _indexText;
set => this.RaiseAndSetIfChanged(ref _indexText, value);
}
public bool IsQRScannerVisible { get; private set; }
IndexPage.xml
<Label
FontSize="14"
HorizontalOptions="Center"
Text="{Binding IndexText}"
TextColor="White"
Margin="0,-26,0,150">
</Label>
<ImageButton
Source="drawable/qrcode_icon.png"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
WidthRequest = "70"
HeightRequest = "70"
MinimumHeightRequest = "70"
MinimumWidthRequest = "70"
BackgroundColor="#004B86"
IsVisible="{Binding IsQRScannerVisible}"
Command="{Binding ScanVerificationCommand}"/>
Solution
you are setting the internal field
_indexText = "Waiting for Identity to be Issued";
doing this bypasses the PropertyChanged
event. Instead use the public property
IndexTest = "Waiting for Identity to be Issued";
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.