我有以下代码,但它无法正常工作。
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1">
<ScrollView VerticalOptions="FillAndExpand">
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="webViewLayout">
<WebView x:Name="webcontentcontrol" Source="{Binding WebViewSource}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill"></WebView>
</StackLayout>
</ScrollView>
</StackLayout>
<StackLayout IsVisible="{Binding IsBusy}"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
<ActivityIndicator IsRunning="{Binding IsBusy}" Style="{StaticResource ActivityIndicatorStyle}"/>
<Label Text="Loading..." IsVisible="{Binding IsBusy}" HorizontalOptions="Center" Style="{StaticResource ActivityIndicatorLabelStyle}"/>
</StackLayout>
</AbsoluteLayout>
Cs文件代码
public AnnouncementPage()
{
InitializeComponent();
BindWebViewControl();
}
protected override void OnAppearing()
{
webViewLayout.IsVisible = false;
IsBusy= true;
}
private async void BindWebViewControl()
{
var result = await _dataService.GetAnnouncement();
webcontentcontrol.Source = result.Data.First().WebViewSource;
IsBusy = false;
webViewLayout.IsVisible = true;
}
问题是标签“正在载入...”没有隐藏,并且活动指示器没有显示在屏幕上。
答案 0 :(得分:1)
如下所示更改您的代码并尝试希望它的帮助:
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<StackLayout x:Name="stkWebview" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1">
<ScrollView VerticalOptions="FillAndExpand">
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="webViewLayout">
<WebView x:Name="webcontentcontrol" Source="{Binding WebViewSource}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill"></WebView>
</StackLayout>
</ScrollView>
</StackLayout>
<StackLayout x:Name="stkLoading"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
<ActivityIndicator IsRunning="true" Style="{StaticResource ActivityIndicatorStyle}"/>
<Label Text="Loading..." HorizontalOptions="Center" Style="{StaticResource ActivityIndicatorLabelStyle}"/>
</StackLayout>
</AbsoluteLayout>
您的代码如下所示:
public AnnouncementPage()
{
InitializeComponent();
BindWebViewControl();
}
protected override void OnAppearing()
{
stkWebview.IsVisible = false;
stkLoading.IsVisible = true;
}
private async void BindWebViewControl()
{
var result = await _dataService.GetAnnouncement();
webcontentcontrol.Source = result.Data.First().WebViewSource;
stkWebview.IsVisible = true;
stkLoading.IsVisible = false;
}