首页 > 解决方案 > 无法在 xamarin 中编辑框架内的条目

问题描述

我正在使用 BindableLayout,在其中,我正在显示项目列表

<StackLayout
   BindableLayout.ItemsSource="{Binding AccountsList}" Spacing="0">
      <BindableLayout.ItemTemplate>
           <DataTemplate>
               <Frame
                  Margin="0,5,0,10"
                  Padding="10">
                  <Label Text="testinnnng"/>
                  <Entry Text="{Binding UserText}"/>//this entry is not allowing the user to click on the UI since it is inside the list item
               </Frame>
          </DataTemplate>
   </BindableLayout.ItemTemplate>
</StackLayout>

这里每一帧都是一个列表项。问题出在列表项内,我有一个输入框。但我无法编辑文本。我尝试了谷歌给出的所有可能的解决方案,但仍然无法编辑该条目。我请求任何人以 xamarin 形式帮助我解决这个问题。

谢谢

标签: androidxamarinxamarin.formsxamarin.androidxamarin.ios

解决方案


就像杰森说的那样,xaml 是无效的。首先将stacklayout放在框架内。

xml:

<StackLayout BindableLayout.ItemsSource="{Binding AccountsList}" Spacing="0">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                <Frame Margin="0,5,0,10" Padding="10">
                    <StackLayout>
                        <Label Text="testinnnng" />
                        <Entry Text="{Binding UserText}" />
                    </StackLayout>
                </Frame>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>

后面的代码:

public partial class Page2 : ContentPage
{
    public ObservableCollection<Info> AccountsList { get; set; }
    public Page2()
    {
        InitializeComponent();
        AccountsList = new ObservableCollection<Info>()
        {
            new Info(){ UserText="A"},
            new Info(){ UserText="B"},
            new Info(){ UserText="C"},
            new Info(){ UserText="D"},

        };

        this.BindingContext = this;
    }
}
public class Info
{
    public string UserText { get; set; }
}

现在可以编辑该条目。

在此处输入图像描述


推荐阅读