-
Notifications
You must be signed in to change notification settings - Fork 459
Don't thrown when tap/selected is null, return null. For deselect. #950
Conversation
@jamesmontemagno thanks for this PR, can you rephrase this part, I'm a little lost in there
|
Whoops -> |
The problem is when you set "SelectedCoffee = null" in the Command it throws an exception because this code is false: so you need to check to see if value is null first. |
I wasn't able to run tests locally, so someone probably needs to pull this PR down. |
I can do it! |
Fixed up my example |
Take a look here -> https://github.com/jamesmontemagno/MyCoffeeApp/blob/master/MyCoffeeApp/MyCoffeeApp/ViewModels/CoffeeEquipmentViewModel.cs#L61 I should be able to do |
@jamesmontemagno I was able to fix it on XCT but is a very ugly fix. So I would say that is a known bug and the workaround is using the object as a parameter. The null check that you added on converters is enough, I believe. Can we merge this? |
Thanks James! <3 |
Did this actually fix the full bug or does AsyncCommand also need to be patched? |
@jamesmontemagno the fix will be on EventToCommandBehavior, you can see my spec here #953, if you have time, please let me know what you think about it (: |
Ahhh gotcha! cool! Did my code do anything? I saw @jfversluis pulled it in.. :) |
@jamesmontemagno I tested yesterday using your code and works like a charm. Now is just a matter to see if my idea is good and safe to implement (: |
Gotcha, so it will be a combination of your fix and my fix that fixes it up fully for me. Got it |
I'm using XCT version 1.2.0 and still facing this issue. Is there anything else I'm missing? This is my code. <ListView
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<ListView.Behaviors>
<xct:EventToCommandBehavior
Command="{Binding SelectItemCommand}"
EventArgsConverter="{StaticResource ItemSelectedEventArgsConverter}"
EventName="ItemSelected" />
</ListView.Behaviors> private Item selectedItem;
public Item SelectedItem
{
get => selectedItem;
set => SetProperty(ref selectedItem, value);
}
public AsyncCommand<Item> SelectItemCommand { get; }
private async Task ExecuteSelectItemCommand(Item item)
{
if (item == null)
return;
SelectedItem = null;
await Application.Current.MainPage.DisplayAlert("Selected", item.Text, "OK");
} |
Description of Change
For example I want to write this in my VM:
And this in my XAML:
Today, this will throw an exception because it it null and is not of the type it is expecting, but that should be allowed.
The only work around is to do something like
AsyncCommand<object>
instead ofAsyncCommand<Coffee>
Bugs Fixed
API Changes
Behavioral Changes
PR Checklist