-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RefreshView executes command on Page loading #6456
Comments
hi @AndreasReitberger, would you like to provide a sample project? |
Sure, I'll create a sample and link it here. |
I created a small repo showing the behavior. I cannot reproduce the issue in my app that the Just set a breaking point to Then click the "Refresh" using Issue_6455.Models;
using System.Diagnostics;
namespace Issue_6455.ViewModels
{
public class LoadingPageViewModel : BaseViewModel
{
#region Properties
int _counter = 0;
public int Counter
{
get => _counter;
set
{
if (_counter == value) return;
_counter = value;
OnPropertyChanged();
}
}
#endregion
#region Constructor
public LoadingPageViewModel()
{
ConnectCommand = new Command(async () => await ConnectAction(), ConnectCommand_CanExcecute);
}
#endregion
#region Commands
public Command ConnectCommand { get; set; }
bool ConnectCommand_CanExcecute()
{
return !IsConnecting;
}
async Task ConnectAction()
{
try
{
Counter++;
IsConnecting = true;
await Task.Delay(2500);
}
catch (Exception exc)
{
// Log error
Debug.WriteLine(exc.Message);
}
IsConnecting = false;
}
#endregion
}
} <?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Issue_6455.Views.LoadingPage"
xmlns:viewModels="clr-namespace:Issue_6455.ViewModels"
>
<ContentPage.BindingContext>
<viewModels:LoadingPageViewModel x:Name="ViewModel" />
</ContentPage.BindingContext>
<Grid>
<RefreshView
IsRefreshing="{Binding IsConnecting}"
Command="{Binding ConnectCommand}"
>
<Grid
RowDefinitions="*,80"
>
<Label
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
>
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="Command fired: " />
<Span Text="{Binding Counter}" />
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<Button
Grid.Row="1"
Text="Refresh"
Command="{Binding ConnectCommand}"
Margin="20,10"
/>
</Grid>
</RefreshView>
</Grid>
</ContentPage> Repo: |
Verified repro on iOS 15.4 with VS 17.3.0 Preview 1.0 [32414.199.main]. Repro project: |
Any news when this will be fixed? |
Reproduced on Windows with VS17.3.0 Preview 2.0. Call stack of first call:
Call stack of second call:
|
The Currently the
|
@AndreasReitberger as a workaround: Add |
I came to this issue too. However, it is explained here that we can use the I no longer experience the double call issue since I specified that the command should only execute when it is not already running. I use CommunityToolkit.Mvvm.Input package and its In GalleryView.xaml
In GalleryViewModel
|
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Still seeing this issue on the latest version. The workaround is working, though. But this should actually be fixed.. The main issue still is, that the |
The documentation now states that setting
It is also the reason why we are experiencing this issue (and probably it is not a bug but by design) because I think always the logic of the app is that we initially call something like We could set I think the issue here is that
When we only need 1., we also receive 2. which we don't actually want in the use case I explained. I think the solution could be:
Example use case in my app: I have a RefreshView and everytime I visit the page, the command gets executed twice. How to repro repeatedly in the app:
How to observe the command being called twice:
|
Thanks for your input. As far as I understood, the For me it does not make sense to trigger the |
The animation is shown is equivalent to IsRefreshing=true |
Hi @janseris !! Thank you for following up! I removed the triaged and verified labels because we're doing a pass on all older issues to see if they are in a different state in the latest public versions. I'll update this one, since you've kindly done that for us! |
i'm facing the exact same behavior, any update on this? |
I can reproduce this same issue on Android |
Found a simple workaround by using Refreshing event instead of Command.
That way it doesn't fall under binding context reapplying. |
Description
I'm using a RefreshView and noticed that the command is fired on the initial page loading.
Is this intended?
Steps to Reproduce
Version with bug
Release Candidate 1 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, I was not able test on other platforms
Affected platform versions
iOS
Did you find any workaround?
Add a "IsStartup" boolean to the CanExecute method for the Command binded to the RefreshView
Relevant log output
No response
The text was updated successfully, but these errors were encountered: