C# 没有MVVM模式的列表绑定元素
我正在开发一个需要显示列表内容的应用程序。问题是我不能使用mvvm。我试图通过直接从cs文件绑定数据来实现这一点。列表已绑定,网格的行数正确。我不知道如何绑定列表项 我试着这样做 绑定列表有效C# 没有MVVM模式的列表绑定元素,c#,android,xaml,xamarin,data-binding,C#,Android,Xaml,Xamarin,Data Binding,我正在开发一个需要显示列表内容的应用程序。问题是我不能使用mvvm。我试图通过直接从cs文件绑定数据来实现这一点。列表已绑定,网格的行数正确。我不知道如何绑定列表项 我试着这样做 绑定列表有效 <dg:DataGrid x:Name="temp" BindingContext="{x:Reference ClassName}" ItemsSource="{Binding list}" SelectionEnabled="True" RowHeight="50"
<dg:DataGrid x:Name="temp" BindingContext="{x:Reference ClassName}"
ItemsSource="{Binding list}" SelectionEnabled="True"
RowHeight="50" HeaderHeight="50" BorderColor="#CCCCCC"
Margin="0,10,0,0" HeaderBackground="#85807a">
尝试将ItemsSource=“{Binding list}”添加到dg:DataGrid:
<dg:DataGrid ItemsSource="{Binding Teams}" SelectionEnabled="True" SelectedItem="{Binding SelectedTeam}" ActiveRowColor="#8899AA">
...
<dg:DataGrid/>
这里供参考。您使用的是哪种特定的数据网格?我从nuget获得,它的Xamarin.Forms.datagrid如果您在条目中硬编码一个值,它会显示吗?是的,它会显示
应该可以工作。您确定您的模型包含该字段中的数据吗?
<dg:DataGridColumn Title="temp" PropertyName="model_field" Width="1.8*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate >
<Entry Text="{Binding model_field}"></Entry>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dg="clr-
namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
x:Class="NamespaceName.ClassName" x:Name="ClassNamex"
BackgroundImage="background.jpg"
NavigationPage.HasBackButton="False">
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ClassName : ContentPage
{
public List<MyModel> list { get; set; }
public ClassName ()
{
list = GeneralServices.selectedAWD.ElemList;
InitializeComponent();
title.Text = "Elements:" +
GeneralServices.selectedAWD.DocumentNumber;
}
}
public class MyModel
{
public string model_field { get; set; }
}
<dg:DataGrid ItemsSource="{Binding Teams}" SelectionEnabled="True" SelectedItem="{Binding SelectedTeam}" ActiveRowColor="#8899AA">
...
<dg:DataGrid/>
<dg:DataGridColumn Title="temp" PropertyName="model_field" Width="1.8*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate >
<Entry Text="{Binding model_field}"></Entry>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>