Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Problem with Buttons isEnabled binding with converter

$
0
0

I don't now if this is a bug of Xamarin.Forms, CarouselView or my code. I have four content views in my CarouselView. At the moment the views are all one and the same page, different objects of course. I have few buttons in the view which should be enabled according to another variable and I have made converter for it. The problem is that the binding doesn't work on iOS on the first page, the other ones are updating correctly when the variable changes. In Android the first and second pages are not updating but the third and fourth are again correctly updated. So the property binding and the converter works correctly but not on all pages. At the pages where the buttons do not correctly update the converter fires only at the start but not more afterwards when the value changes. On the other pages the converter fires every time the value changes.

I also tried the buttons only at my start page where I have my CarouselView but the buttons do not update also there correctly.

Part of the page with buttons:

                <StackLayout.Resources>
                    <ResourceDictionary>
                        <utils:IntToBoolWithParameterConverter x:Key="IntToBoolWithParameter" />
                    </ResourceDictionary>
                </StackLayout.Resources>

                <Button
                    Text="BAT1"
                    StyleId="0"
                    Clicked="OnStringButtonClicked"
                    IsVisible="{Binding Source={x:Static Application.Current},
                                Path=BatteryData.CurrentSystem.StringCount,
                                Converter={StaticResource IntToBoolWithParameter},
                                ConverterParameter=1}"/>

                <Button
                    Text="BAT2"
                    StyleId="1"
                    Clicked="OnStringButtonClicked"
                    IsVisible="{Binding Source={x:Static Application.Current},
                                Path=BatteryData.CurrentSystem.StringCount,
                                Converter={StaticResource IntToBoolWithParameter},
                                ConverterParameter=2}"/>

                <Button
                    Text="BAT3"
                    StyleId="2"
                    Clicked="OnStringButtonClicked"
                    IsVisible="{Binding Source={x:Static Application.Current},
                                Path=BatteryData.CurrentSystem.StringCount,
                                Converter={StaticResource IntToBoolWithParameter},
                                ConverterParameter=3}"/>
                <Button
                    Text="BAT4"
                    StyleId="3"
                    Clicked="OnStringButtonClicked"
                    IsVisible="{Binding Source={x:Static Application.Current},
                                Path=BatteryData.CurrentSystem.StringCount,
                                Converter={StaticResource IntToBoolWithParameter},
                                ConverterParameter=4}"/>
</StackLayout>

Converter

public class IntToBoolWithParameterConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            string strParam = parameter as string;
            int reference = 0;

            if (!String.IsNullOrEmpty(strParam))
            {
                Int32.TryParse(strParam, out reference);
            }

            return reference <= (int)value;
        }

        public object ConvertBack(object value, Type targetType,
                                  object parameter, CultureInfo culture)
        {
            return 0;
        }
    }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>