问题描述
我正在使用 BindableLayout 并且在其中显示了一个项目列表
<StackLayout
BindableLayout.ItemsSource="{Binding AccountsList}" Spacing="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame
Margin="0,5,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 形式帮助我解决这个问题。
谢谢
解决方法
就像 Jason 所说的,xaml 是无效的。先把stacklayout放到frame里面。
XML:
<StackLayout BindableLayout.ItemsSource="{Binding AccountsList}" Spacing="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Margin="0,5,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; }
}
现在可以编辑条目。