【问题标题】:Not able to edit the entry inside the frame in xamarin无法在 xamarin 中编辑框架内的条目
【发布时间】:2021-05-24 23:37:38
【问题描述】:

我正在使用 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 形式帮助我解决这个问题。

谢谢

【问题讨论】:

  • 您是说在运行应用程序时无法在输入框中输入内容吗?而且 XAML 无效 - 我相信 Frame 只能有一个孩子,text 不是有效属性
  • 您使用的是哪个 IDE? VS 会强调您的 xaml 包含 @Jason 在构建之前提到的错误。
  • 我正在使用视觉工作室。问题是一旦列表项显示在每个列表项中,我将显示一个标签和一个条目。因此,当我尝试编辑输入框或单击输入框时,它不允许用户单击该条目。您能告诉我如何启用该条目吗?
  • 您不需要做任何事情。 UserText 属性是只读的吗?并且请确保您发布的代码是有效的,当发布的代码有明显错误时很难提出建议。
  • 是的,用户文本是我将数据绑定到编辑文本的属性...在 UI 上,该条目显示了我正在绑定的预填充数据。但是当我尝试编辑时,它不允许编辑输入框。

标签: android xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

就像 Jason 所说,xaml 无效。先把stacklayout放到frame里面。

Xaml:

<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; }
}

现在可以编辑条目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多