Monday, August 15, 2022
HomeiOS Developmentc# - Xamarin kinds iOS app, Command button not firing when pressed

c# – Xamarin kinds iOS app, Command button not firing when pressed

[ad_1]

I’ve tried every little thing I might discover on the web and nonetheless can’t get the occasion to fireplace. My web page comprises 2 buttons as you possibly can see which fireplace within the Simulator however not on my iphone. I’ve tried many various options discovered on the web and the one I’m displaying right here is the final one I tried.

Right here is the buttons outlined for my part:

    <Button Command="{Binding Supply={RelativeSource AncestorType={x:Kind ViewModel:EditViewModel}}, Path=UpdateMileage}" CommandParameter="{Binding .}" IsEnabled="True" Textual content="Replace" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="1" TextColor="Black" Margin="4"/>
    <Button Command="{Binding Supply={RelativeSource AncestorType={x:Kind ViewModel:EditViewModel}}, Path=Cancel}" CommandParameter="{Binding .}" Textual content="Cancel" BackgroundColor="Yellow" Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="2" TextColor="Black" Margin="4"/>

The viewModel code is as follows;

    public ICommand UpdateMileage
    {
        get; set;
    }

    public EditViewModel()
    {
        UpdateMileage = new Command(UpdateMileageData);

        MileageTableDefination mileage = new MileageTableDefination();
        mileage = Software.Present.Properties["MileageData"] as MileageTableDefination;
        SDate = Convert.ToDateTime(mileage.Date);
        EntMiles = mileage.Miles.ToString();
        EntGas = mileage.Fuel.ToString();
        EntCost = mileage.Worth.ToString();
        if (mileage.Word != null)
            EntNote = mileage.Word.ToString();
        EntId = mileage.Id;
    }

    public async void UpdateMileageData()
    {
        Analytics.TrackEvent("In UpdateMileageData High ");
        int autoId = Convert.ToInt32(Software.Present.Properties["autoId"]);
        //Analytics.TrackEvent("Mileage Knowledge in Enter Mileage: AutoId " + autoId);
        error = false;
        IsVisibleLabel = false;

        if (EntMiles == "0" || EntMiles == null)
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Miles Pushed Should Be Numeric";
        }
        else if (!System.Textual content.RegularExpressions.Regex.IsMatch(EntMiles, @"^[0-9]d*(.d+)?$"))
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Miles Pushed Should Be Numeric";
        }
        else if (Convert.ToDecimal(EntMiles) > 1000)
        {
            error = true;
            //IsVisibleLabel = true;
            EntError = "Miles Pushed Since Final Fillup";
        }
        if (EntGas == "0" || EntGas == null)
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Fuel Used Should Be Numeric";
        }
        else if (!System.Textual content.RegularExpressions.Regex.IsMatch(EntGas, @"^[0-9]d*(.d+)?$"))
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Fuel Used Should Be Numeric";
        }
        if (EntCost == "0" || EntCost == null)
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Value Should Be Numeric";
        }
        else if (!System.Textual content.RegularExpressions.Regex.IsMatch(EntCost, @"^[0-9]d*(.d+)?$"))
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Value Should Be Numeric";
        }
        else if (Convert.ToDecimal(EntCost) > 300.00m)
        {
            error = true;
            IsVisibleLabel = true;
            EntError = "Value Should Be Numeric And < $300";
        }
        Analytics.TrackEvent("In UpdateMileageData After If's Error = " + error);
        if (!error)
        {
            miles.Date = SDate.Date;
            miles.StrDate = SDate.Date.ToString("MM/dd/yyyy");
            miles.Miles = Convert.ToDecimal(EntMiles);
            miles.Fuel = Convert.ToDecimal(EntGas);
            miles.Id = EntId;
            miles.CarId = autoId;
            miles.MPG = Math.Spherical(Convert.ToDecimal(EntMiles) / Convert.ToDecimal(EntGas), 3);
            miles.Worth = Convert.ToDecimal(EntCost);
            miles.Word = EntNote;
            MileageItemRepository mir = new MileageItemRepository();
            var outcomes = await mir.UpdateMileageAsync(miles);
            Analytics.TrackEvent("In UpdateMileageData Outcomes = " + outcomes);
            if (outcomes == 1)
            {
                Software.Present.Properties["UpdatedData"] = miles;
                var nav = MyNavigation.GetNavigation();
                await nav.PushAsync(new ViewMileage());
            }
        }
    }

As you possibly can see from my code I’ve logging statements and they’re by no means reached. Any assist can be a lot appreciated. Thanks upfront!

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments