我有一個DataGrid
,遵循XAML:數據表沒有被綁定到DataContext的一個DataGrid
<DataGrid ItemsSource="{Binding Path=propCollection}"
SelectedItem="{Binding Path=SelectProp, Mode=TwoWay}"
Margin="-1,159,0,0"
RowDetailsVisibilityMode="Visible"
AreRowDetailsFrozen="False"
CanUserReorderColumns="False"
CanUserSortColumns="True"
CanUserResizeRows="False"
SelectionUnit="FullRow"
AlternatingRowBackground="{x:Null}"
SelectionChanged="dgProprietarios_SelectionChanged"
AlternationCount="0"
Height="200"
HorizontalAlignment="Left"
Name="dgProprietarios"
VerticalAlignment="Top"
Width="645"
AutoGenerateColumns="False">
<...Columns...>
</DataGrid>
在我Window_Loaded我做到以下幾點:
dgProprietarios.DataContext = new ProprietariosViewModel(new Dictionary<string, string>());
我ProprietariosViewModel是如下:
public CollectionProprietarios propCollection { get; set; }
public ProprietariosViewModel(Dictionary<string, string> Where)
{
propCollection = new CollectionProprietarios(Where);
}
的CollectionProprietarios類繼承的ObservableCollection,並有下面的代碼:
public CollectionProprietarios(Dictionary<string, string> Where)
{
Add(new Dados(Where));
}
public new void Add(Dados dados)
{
base.Add(dados);
}
類Dados有以下代碼:
public DataTable ProprietariosRetorno { get; private set; }
public Dados(Dictionary<string, string> Where)
{
var ado = new ADO();
ProprietariosRetorno = ado.RetornaSelect(MontaQuery(Where));
}
功能MontaQuery只是創建一個字符串包含一個SELECT子句和RetornaSelect執行此查詢。
該類別ADO,當instanciated只是創建數據庫和表,如果它不存在。
問題是,所有這些都在起作用。在調試時,我可以檢索DataContext中的值,並且它包含具有值的DataTable。但出於某種原因,它在程序運行時不會出現在DataGrid上。
所以問題是,我做錯了什麼?
在'公共的DataTable ProprietariosRetorno {獲得;私人設置; }'我已經嘗試刪除私人設置並用set替換它。沒有運氣。 ( –