Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some bugs in Xamarin Forms 2.3.3
public class ListViewPage : ContentPage
{
//Tree bugs (iOS):
//1. Important. If spinner is running, and you press the Entry, then the listview will get unaligned.
// to reproduce. Just start the project, click the entry, and then click the Refresh button.
//2. If changeExecute is changed while running, it will kill the spinner.
// to reproduce use pull to refresh, and se that the spinner disapairs before the list is updated.
//3. If can execute returns false, the spinner will start, but the command will never execute.
// to reproduce, just uncomment "_canExecute = true;" and do a pull to refresh.
readonly ListView _listView;
private bool? _canExecute;
readonly Command _refreshCommand;
public ListViewPage()
{
this.Padding = new Thickness(0, 20, 0, 0);
_canExecute = true; //Start bug 3 if commented out, and starts bug 2 if not.
_refreshCommand = new Command(RefreshCommandLogic, () => _canExecute ?? false);
_listView = new ListView
{
HeaderTemplate = new DataTemplate(() => {
return new StackLayout { Children = { new Label { Text = "Test 456" } } };
}),
Header = new StackLayout { Children = { new Label { Text = "Test 123" } } },
IsPullToRefreshEnabled = true,
IsRefreshing = true,
RefreshCommand = _refreshCommand,
ItemsSource = new string[0]
};
_listView.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(ListView.ItemsSource))
_listView.IsRefreshing = false;
};
Content = new StackLayout
{
Children = {
new Button { Text = "ClearView", Command = new Command(() => Application.Current.MainPage = new ListViewPage()) },
new Entry { Placeholder = "TestTExt" },
new Button { Text = "Toggle", Command = new Command(() => _listView.IsRefreshing = !_listView.IsRefreshing) },
new Button { Text = "Refresh", Command = new Command(() => {
_listView.IsRefreshing = true;
RefreshCommandLogic();
})
},
new Grid {
RowDefinitions = {
new RowDefinition { Height = 300 }
},
Children = {
_listView
}
}
}
};
}
private async void RefreshCommandLogic()
{
_listView.IsRefreshing = true;
//Will kill spinner early:
//It is a bug, but is this the correct way of using this? Should be => parameter == something, yes/no.
//However, it will start the spinner, but not execute the command.
if (_canExecute != null)
{
_canExecute = false;
_refreshCommand.ChangeCanExecute();
}
await Task.Delay(2000);
_listView.ItemsSource = Enumerable.Range(0, 1)
.Select(i => Guid.NewGuid().ToString("N"))
.ToArray();
if (_canExecute != null)
{
_canExecute = true;
_refreshCommand.ChangeCanExecute();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.