微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我有一个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 举报,一经查实,本站将立刻删除。