[英]How to create a dynamic table in Visual Studio 2013?
I want to make a table similar to a UITableView in iOS. 我想制作一个类似于iOS中的UITableView的表。 How can I do this in visual studio using GUI and C#? 如何在Visual Studio中使用GUI和C#做到这一点? I am using a Windows Form. 我正在使用Windows窗体。
I tried searching online but I couldn't find any tutorials. 我尝试在线搜索,但找不到任何教程。
Also, I'm new to C# so sorry if it's an easy solution. 另外,我是C#的新手,所以很抱歉,这是一个简单的解决方案。
Lets say we have a class: 可以说我们有一堂课:
class SomeClass
{
public string FirstValue { get; set; }
public string SecondValue { get; set; }
}
And a Window: 和一个窗口:
<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox ItemsSource="{Binding}" Background="LightBlue">
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel Background="LightBlue">
<TextBlock Text="{Binding Path=FirstValue}" Background="Brown"/>
<TextBlock Text="{Binding Path=SecondValue}" Background="Green"/>
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
And this code behind: 后面的代码如下:
public partial class MainWindow : Window
{
private IEnumerable<SomeClass> datasource;
public MainWindow()
{
InitializeComponent();
datasource = new[]
{
new SomeClass{FirstValue = "some", SecondValue = "another"},
new SomeClass{FirstValue = "more",SecondValue = "yet another"}
};
this.DataContext = datasource;
}
}
The result would be: 结果将是:
Just to demonstrate how easy WPF is. 只是为了演示WPF有多简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.