Hello,
I've encountered a problem that looks like so strange and I don't know how to deal with it. I tried a lot of combinations but nothing worked.
I've the "main" class 'MainWindow.cs' which has :
MainWindow.xaml : 1st row doesn't work, 2nd works
Datas.cs :
And the inheritance of INotifyPropertyChanged etc...
ConfigTabCameras :
ViewTabCameras.cs :
And finally my custom UserControl as a GridView TabCameras.cs :
TabCameras.xaml :
So the MainWindow is supposed to include my custom controls but they don't display anything. However, when I add a GridView control in my MainWindow with the same binding, it works perfectly. I tried to change the position of "dataContext" in many classes but nothing changed.
So, how can I have my custom controls in my MainWindow which display everything returned by my SQL query and saved in my Datas.cs please ?
I hope I was clear enough, I don't think I used the easier way...
Thanks !
I've encountered a problem that looks like so strange and I don't know how to deal with it. I tried a lot of combinations but nothing worked.
I've the "main" class 'MainWindow.cs' which has :
Datas datas =
new
Datas();
ConfigTabCameras ctc = new ConfigTabCameras(datas);
this
.DataContext = datas;
MainWindow.xaml : 1st row doesn't work, 2nd works
<
custom:TabCameras
/>
<
telerik:RadGridView
ItemsSource
=
"{Binding DatasTabCameras}"
/>
Datas.cs :
private
ObservableCollection<ViewTabCameras> datasTabCameras;
public
ObservableCollection<ViewTabCameras> DatasTabCameras
{
get
{
if
(
this
.datasTabCameras ==
null
)
{
this
.datasTabCameras =
new
ObservableCollection<ViewTabCameras>();
}
return
this
.datasTabCameras;
}
set
{
this
.EventPropertyChanged(
"DatasTabCameras"
);
}
}
public
Datas()
{
}
And the inheritance of INotifyPropertyChanged etc...
ConfigTabCameras :
public
class
ConfigTabCameras : AbstractSql
{
public
ConfigTabCameras(Datas datas)
{
this
.configurationDatas = datas;
ConfigurationTabCameras();
}
private
void
TabCamerasConfiguration()
{
connect.dbConnect();
command.CommandText =
"SELECT f1, f2, f3 "
+
"FROM t1ORDER BY f1"
;
command.CommandType = CommandType.Text;
command.Connection = connect.getSqlConnection();
dataReader = command.ExecuteReader();
while
(dataReader.Read())
{
ViewTabCameras vtc =
new
ViewTabCameras();
vtc.Field1 = dataReader[
"f1"
].ToString();
vtc.Field2 =
int
.Parse(dataReader[
"f2"
].ToString());
vtc.Field3 =
int
.Parse(dataReader[
"f3"
].ToString());
donneesConfiguration.DatasTabCameras.Add(vtc);
}
command.Dispose();
dataAdapter.Dispose();
connect.dbDisconnect();
}
}
ViewTabCameras.cs :
private
string
field1;
private
int
field2;
private
int
field3;
public
string
Field1
{
get
{
return
this
.field1;
}
set
{
this
.field1= value;
this
.EventPropertyChanged(
"Field1"
);
}
}
// Same for Field2 and 3...
And finally my custom UserControl as a GridView TabCameras.cs :
private
Donnees donnees;
public
TabCameras()
{
datas =
new
Datas();
//this.DataContext = datas;
InitializeComponent();
}
TabCameras.xaml :
<
telerik:RadGridView
ItemsSource
=
"{Binding DatasTabCameras}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Field1}"
Header
=
"Field 1"
UniqueName
=
"Field1"
/>
<
telerik:GridViewComboBoxColumn
Header
=
"Field 2"
ItemsSource
=
"{Binding Field2}"
UniqueName
=
"Field2"
DataMemberBinding
=
"{Binding Field2}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Field3}"
Header
=
"Field 3"
UniqueName
=
"Field3"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
So the MainWindow is supposed to include my custom controls but they don't display anything. However, when I add a GridView control in my MainWindow with the same binding, it works perfectly. I tried to change the position of "dataContext" in many classes but nothing changed.
So, how can I have my custom controls in my MainWindow which display everything returned by my SQL query and saved in my Datas.cs please ?
I hope I was clear enough, I don't think I used the easier way...
Thanks !