我与WPF总初学者,我要尽量作出有约束力的WPFWPF Datagrid的约束力不显示值
这里的DataGrid是XAML代码
<Grid x:Name="LayoutRoot">
<Grid HorizontalAlignment="Left" Height="440" VerticalAlignment="Top" Width="632">
<DataGrid HorizontalAlignment="Left" Height="420" Margin="10,10,0,0" VerticalAlignment="Top" Width="603" ItemsSource="{Binding Source=MailCollection}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="id" Binding="{Binding Id}"/>
<DataGridTextColumn Header="nazwa" Binding="{Binding Name}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
这里是MailTpl类
public class MailTpl
{
public string Id { get; set; }
public string Name { get; set; }
}
这里是我如何做绑定
public partial class WindowDataGridTest : Window
{
ObservableCollection<MailTpl> _MailCollection = new ObservableCollection<MailTpl>();
public ObservableCollection<MailTpl> MailCollection { get { return _MailCollection; } }
public WindowDataGridTest()
{
_MailCollection.Add(new MailTpl { Id= "abbb", Name = "badfasdf" });
_MailCollection.Add(new MailTpl { Id = "asasdfasdfdf", Name = "basdfasdfaa" });
this.InitializeComponent();
// Insert code required on object creation below this point.
}
}
我不知道为什么它不起作用。任何线索?网格不显示任何值。
谢谢你的工作。我将更多地阅读它。 – Robert
感谢“Trace WPF”提示,它帮助我了解了我的问题! – MSE