绑定一个ObservableCollection到WPF数据网格:电网保持为空 [英] Bind an ObservableCollection to a wpf datagrid : Grid stays empty
本文介绍了绑定一个ObservableCollection到WPF数据网格:电网保持为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个的ObservableCollection
绑定到WPF DataGrid中。
我的的ObservableCollection
不是空的,但是,我的DataGrid留空:
I would like to bind an ObservableCollection
to wpf datagrid.
My ObservableCollection
is not empty, but, my datagrid stay empty :
public partial class Fenetre_EvtCode : Window
{
ObservableCollection<EvtCode> glb_ObservableEvtCode;
public Fenetre_EvtCode()
{
InitializeComponent();
EvtCode myEvt = new EvtCode();
glb_ObservableEvtCode = myEvt.GetAllEvtCode();
}
}
下面是我的XAML:
<DataGrid Foreground="Aqua" Name="myDataGridEvtCode" AutoGenerateColumns="True" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Height="453" ItemsSource="{Binding glb_ObservableEvtCode}" ></DataGrid>
我再说一遍:我看着在调试,我的的ObservableCollection
不是空的。
谁知道为什么马DataGrid中留下空的?
Anyone know why ma datagrid stay empty ?
推荐答案
您需要绑定到一个公共财产
public ObservableCollection<EvtCode> ObservableEvtCode
{
get
{
return this.glb_ObservableEvtCode;
}
}
和XAML:
<DataGrid
...
DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}"
ItemsSource="{Binding ObservableEvtCode}" >
</DataGrid>
的编辑:的也看到这个的answer
这篇关于绑定一个ObservableCollection到WPF数据网格:电网保持为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文