【发布时间】:2019-02-04 22:38:45
【问题描述】:
我正在开发一个 Xamarin Forms 应用程序。我想在获取数据并将其绑定到 Web API 的 ListView 控件时显示 ActivityIndicator。在我的代码中,ActivityIndicator 根本不显示。我正在使用带有 Xamarin 4.10 的 Visual Studio 2017。
以下是我的代码。
代码背后
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TestPage : ContentPage
{
private SfListView listView;
private ActivityIndicator activityIndicator;
public TestPage()
{
InitializeComponent();
StackLayout mainStackLayout = new StackLayout();
activityIndicator = new ActivityIndicator()
{
IsRunning = true,
IsEnabled = true,
IsVisible = true
};
listView = new SfListView()
{
SelectionMode = SelectionMode.None,
BackgroundColor = Color.White
};
mainStackLayout.Children.Add(activityIndicator);
mainStackLayout.Children.Add(listView);
this.Content = mainStackLayout;
this.Title = "Dashboard";
}
protected override void OnAppearing()
{
SummaryRepository viewModel = new SummaryRepository();
listView.ItemsSource = viewModel.Summary;
listView.ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid();
var bookName = new Label
{
BackgroundColor = Color.White,
FontSize = 16,
TextColor = Color.FromHex("#1A237E")
};
var bookDescription = new Label
{
BackgroundColor = Color.White,
FontSize = 16,
HorizontalTextAlignment = TextAlignment.End,
TextColor = Color.FromHex("#EC407A")
};
bookName.SetBinding(Label.TextProperty, new Binding("Name"));
bookDescription.SetBinding(Label.TextProperty, new Binding("Amount"));
grid.Children.Add(bookName);
grid.Children.Add(bookDescription, 1, 0);
return grid;
});
activityIndicator.IsRunning = false;
base.OnAppearing();
}
}
XAML 文件
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="eWallet.Pages.TestPage">
<ContentPage.Content>
<StackLayout>
</StackLayout>
</ContentPage.Content>
非常感谢任何帮助。
【问题讨论】:
标签: c# xamarin.forms visual-studio-2017 activity-indicator