Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Xamarin中的Ivalue转换器属性_Xaml_Xamarin_Xamarin.forms - Fatal编程技术网

Xaml Xamarin中的Ivalue转换器属性

Xaml Xamarin中的Ivalue转换器属性,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我有以下转换器,它具有两个属性: public class ProgressConverter : BindableObject, IMarkupExtension, IValueConverter { public static readonly BindableProperty CurrentProgressProperty = BindableProperty.Create("CurrentProgress", typeof(int), typeof(Progre

我有以下转换器,它具有两个属性:

public class ProgressConverter : BindableObject, IMarkupExtension, IValueConverter 
    {
        public static readonly BindableProperty CurrentProgressProperty = BindableProperty.Create("CurrentProgress", typeof(int), typeof(ProgressConverter));
        public static readonly BindableProperty GoalProgressProperty = BindableProperty.Create("GoalProgress", typeof(int), typeof(ProgressConverter));
        public int CurrentProgress
        {
            get { return(int) GetValue(CurrentProgressProperty); }
            set { SetValue(CurrentProgressProperty, value);}
        } 
        public int GoalProgress
        {
            get { return (int)GetValue(GoalProgressProperty); }
            set { SetValue(GoalProgressProperty, value);}
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double progress = (double)CurrentProgress / (double)GoalProgress;
            return progress;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            //throw new NotImplementedException();
            return this;
        }
        object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
        {
            return ProvideValue(serviceProvider);
        }
    }
我在progressbar中使用它来设置这样的进度(这很好,没问题,取2除以5,然后将结果放入progressbar进度中):

Itemsource设置:

public BadgeView(BadgesGroup badgesGroup)
        {
            InitializeComponent();
            BadgeLogo.Source = badgesGroup.Logo;
            var cardsview = new CardsView
            {
                IsClippedToBounds = true,
                IsCyclical = true,
                MoveWidthPercentage = 0.3,
                WidthRequest = 250,
                HeightRequest=250,
                ItemsSource = badgesGroup.Badges,
                ItemTemplate = new DataTemplate(() => new BadgePopUp())
            };
            cardsview.Children.Add(new IndicatorsControl());
            cardsview.Children.Add(new RightArrowControl());
            cardsview.Children.Add(new LeftArrowControl());
            card.Children.Add(cardsview);
        }
我如何使其符合第1点

如何使转换器从绑定中获取如下值:

<ProgressBar x:Name="Progressbar" ProgressColor="Purple" 
                 Progress="{Binding Converter={local:ProgressConverter CurrentProgress={Binding xCurrentProgress},GoalProgress={Binding xGoalProgress}}}">
    </ProgressBar>


因为使用上述代码将导致CurrentProgress和GoalProgress的值都通过0,而不是存储在其中的实际值。

您的问题很模糊,请具体说明您想做什么achieve@FreakyAli更新的问题更清楚,谢谢。我现在没有看到任何变化!我希望我的转换器采用如下绑定值:。。此代码将导致CurrentProgress和GoalProgress的值均通过0,而不是其中存储的实际值。@user2596181您好,我需要知道CardView中ItemSource的代码,您可以共享它。我会检查ItemSource的mdoel。这里可能不需要使用转换器。
public class badge {
string Name {get;set;}
string Description {get;set;}
int xCurrentProgress {get;set;}
int xGoalProgress {get;set;}
}
public BadgeView(BadgesGroup badgesGroup)
        {
            InitializeComponent();
            BadgeLogo.Source = badgesGroup.Logo;
            var cardsview = new CardsView
            {
                IsClippedToBounds = true,
                IsCyclical = true,
                MoveWidthPercentage = 0.3,
                WidthRequest = 250,
                HeightRequest=250,
                ItemsSource = badgesGroup.Badges,
                ItemTemplate = new DataTemplate(() => new BadgePopUp())
            };
            cardsview.Children.Add(new IndicatorsControl());
            cardsview.Children.Add(new RightArrowControl());
            cardsview.Children.Add(new LeftArrowControl());
            card.Children.Add(cardsview);
        }
<ProgressBar x:Name="Progressbar" ProgressColor="Purple" 
                 Progress="{Binding Converter={local:ProgressConverter CurrentProgress={Binding xCurrentProgress},GoalProgress={Binding xGoalProgress}}}">
    </ProgressBar>