Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定文本需要在Xamarin中重新加载页面_C#_.net_Xamarin_.net Core_Binding - Fatal编程技术网

C# 绑定文本需要在Xamarin中重新加载页面

C# 绑定文本需要在Xamarin中重新加载页面,c#,.net,xamarin,.net-core,binding,C#,.net,Xamarin,.net Core,Binding,我正在研究Xamarin.表单应用程序。我在ViewModel页面中设置了一个条件,并通过绑定更改标签文本和图像按钮的可见性 但问题是,当我打开页面时,屏幕是空的,但当我刷新页面时,它会显示文本 下面是xml和.cs页面的代码 IndexViewModel.cs public override async Task InitializeAsync(object navigationData) { var firstname = await SecureStorag

我正在研究Xamarin.表单应用程序。我在ViewModel页面中设置了一个条件,并通过绑定更改标签文本和图像按钮的可见性

但问题是,当我打开页面时,屏幕是空的,但当我刷新页面时,它会显示文本

下面是xml和.cs页面的代码

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);
    }
    private string _indexText;
    public string IndexText
    {
        get => _indexText;
        set => this.RaiseAndSetIfChanged(ref _indexText, value);
    }

    public bool IsQRScannerVisible { get; private set; }
可绑定属性

    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);
    }
    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}"/>

您正在设置内部字段

_indexText = "Waiting for Identity to be Issued";
这样做会绕过
PropertyChanged
事件。而是使用公共财产

IndexTest = "Waiting for Identity to be Issued";

感谢文本部分工作正常,但图像按钮仍需要刷新
IsQRScannerVisible
未调用
RaiseAndSetIfChanged