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
以xamarin形式更改了一个名为infinely的元素属性_Xamarin_Xamarin.forms_Timepicker - Fatal编程技术网

以xamarin形式更改了一个名为infinely的元素属性

以xamarin形式更改了一个名为infinely的元素属性,xamarin,xamarin.forms,timepicker,Xamarin,Xamarin.forms,Timepicker,我在xamarin窗体应用程序中有一个自定义时间选择器渲染器 在我的生活中,我有 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); try {

我在xamarin窗体应用程序中有一个自定义时间选择器渲染器

在我的生活中,我有

protected override void OnElementPropertyChanged(object sender, 

    PropertyChangedEventArgs e)
            {
                base.OnElementPropertyChanged(sender, e);
                try
                {

                    if (e.PropertyName == iOSCustomTimePicker.TimeProperty.PropertyName)
                    {
                        var temp = sender as iOSCustomTimePicker;   
                        picker.Hour = temp.Time.Hours;
                        picker.Minute = temp.Time.Minutes;
                        //TimeSpan value = new TimeSpan(8, 0, 0);
                        //this.Element.SetValue(iOSCustomTimePicker.TimeProperty, value);
                    }

                }
                catch (Exception e1)
                {
                }
            }
我在xaml中使用它

<control:iOSCustomTimePicker x:Name="cli_staffrequest_addShiftTime_timePicker1" Grid.Column="2" Grid.Row="1" Time="{Binding ShiftEndTimeSelected}" 
          HorizontalOptions="Fill" VerticalOptions="Fill" StyleId="uit_staffHiring_addShifts__timePicker1"/>

因此,当在ViewModel中选择的ShiftEndTimes发生更改时,我在OnElementPropertyChanged中得到了一个点击,并更改了时间

现在我的问题是,有时候我会在OnElementPropertyChanged中获得无限的点击率 从而无限地调用垃圾收集器。如何找出问题所在。我对xamarin的形式是完全陌生的

对不起,英语不好

我认为这些话再次引发了事件:

base.OnElementPropertyChanged(sender, e);

如果在事件处理程序上采用这种方式,可能不会发生这种情况(您需要测试):

picker.Hour = temp.Time.Hours;
picker.Minute = temp.Time.Minutes;
try
{
    if (e.PropertyName == iOSCustomTimePicker.TimeProperty.PropertyName)
    {
        var temp = sender as iOSCustomTimePicker;   
        picker.Hour = temp.Time.Hours;
        picker.Minute = temp.Time.Minutes;
    }
    else
        base.OnElementPropertyChanged(sender, e);
}
catch (Exception e1)
{

}