专注于条目并滚动到可视化集合中的条目

问题描述

我有一个collectionview,该视图创建了一个问题列表,当我单击“发送”时,如果没有填写任何条目,我希望该应用程序集中精力,同时向下滚动到该条目,我该怎么办?在这一点上,我有一个行为体,可以验证条目是否已填充,然后显示红色边框,是否可以不使用该行为?,谢谢。

CollectionView

<CollectionView  ItemsSource="{Binding Path=PerguntasVM}"
                 HorizontalScrollBarVisibility="Never"
                 VerticalScrollBarVisibility="Never"
                 ItemTemplate="{StaticResource Questoestemplates}"
                 IsGrouped="True"
                 Margin="0,5,0">

  <CollectionView.GroupHeaderTemplate>
       <DataTemplate>
            <StackLayout Margin="0,5">
                  <Label Text="{Binding Path=Ds_DescricaoPergunta}"
                      FontSize="18"/>
                  <BoxView BackgroundColor="LightSkyBlue" HeightRequest="2"/>
            </StackLayout>
        </DataTemplate>
   </CollectionView.GroupHeaderTemplate>
</CollectionView>
                      

-模板

 <DataTemplate x:Key="RespCurtaTemplate">
            <FlexLayout Direction="Row" AlignItems="Center"
                            AlignContent="Center" Margin="0,10">
                    <Label Text="R: "/>

                <render:ExtendedEntry Placeholder="Resposta Curta:" MaxLength="90" ErrorText=" 
                                          {Binding Path=NotValidMessageError}"
                                          BorderErrorColor="Red"
                                          Text="{Binding Path=Resposta_Alpha}"
                                          IsBorderErrorVisible="{Binding Path=IsNotValid}"
                                          FlexLayout.AlignSelf="Auto"
                                          FlexLayout.Grow="0.9">
                        <render:ExtendedEntry.Behaviors>
                            <behaviors:EmptyEntryValidatorBehavior />
                        </render:ExtendedEntry.Behaviors>
                    </render:ExtendedEntry>
                </FlexLayout>
     
</DataTemplate> 

-bevahior用于放置边缘

public class EmptyEntryValidatorBehavior : Behavior<ExtendedEntry>
{
    ExtendedEntry control;
    string _placeHolder;
    Xamarin.Forms.Color _placeHolderColor;

    protected override void OnAttachedTo(ExtendedEntry bindable)
    {
        bindable.TextChanged += HandleTextChanged;
        bindable.PropertyChanged += OnPropertyChanged;

        control = bindable;
        _placeHolder = bindable.Placeholder;
        _placeHolderColor = bindable.PlaceholderColor;
    }

    void HandleTextChanged(object sender,TextChangedEventArgs e)
    {
        if (!string.IsNullOrEmpty(e.NewTextValue))
        {
            ((ExtendedEntry)sender).IsBorderErrorVisible = false;
        }
        //((ExtendedEntry)sender).AutoSize = EditorAutoSizeOption.TextChanges;
    }

    protected override void OnDetachingFrom(ExtendedEntry bindable)
    {
        bindable.TextChanged -= HandleTextChanged;
        bindable.PropertyChanged -= OnPropertyChanged;
    }

    void OnPropertyChanged(object sender,System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == ExtendedEntry.IsBorderErrorVisibleProperty.PropertyName && control != null)
        {
            if (control.IsBorderErrorVisible)
            {
                control.Placeholder = control.ErrorText;
                control.PlaceholderColor = control.BorderErrorColor;
                control.Text = string.Empty;
                //control.Focus();
                //return;
            }

            else
            {
                control.Placeholder = _placeHolder;
                control.PlaceholderColor = _placeHolderColor;
            }

        }
    }
}

随后是屏幕的照片,当我单击按钮时,我希望它没有被填充时将对准焦点,同时滚动到所有条目中的单个条目。SCREEN IMAGE >

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)