我想在 app.xaml.cs 中定义的类数组的 xaml 数据中显示。
这是我所做的。
保存数据的类。个人.cs
public class Person : INotifyPropertyChanged
{
#region Constructors and Destructors
public Person(int id, string name)
{
this.Name = name;
this.Id = id;
}
#endregion
#region Public Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Public Properties
public int Id { get; set; }
public string Name { get; set; }
#endregion
#region Methods
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
像这样在 App.xaml.cs 中声明了 Person。
public partial class App : Application
{
public static Person[] People =
{
new Person(1, "John"),
new Person(2, "Jake"),
new Person(3, "James"),
new Person(4, "Jack")
};
}
我想在 xaml 中显示数据。我似乎无法弄清楚该怎么做。
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Height="23" TextWrapping="Wrap" Text="id"/>
<TextBox Height="23" TextWrapping="Wrap" Text="name"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Height="23" TextWrapping="Wrap" Text="id"/>
<TextBox Height="23" TextWrapping="Wrap" Text="name"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Height="23" TextWrapping="Wrap" Text="id"/>
<TextBox Height="23" TextWrapping="Wrap" Text="name"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Height="23" TextWrapping="Wrap" Text="id"/>
<TextBox Height="23" TextWrapping="Wrap" Text="name"/>
</StackPanel>
</StackPanel>
谢谢。