I have 4 listbox items that are containing checkbox items. I am trying to bind them from the same Dataset but it seems I am not doing it right.
Also I would like to know if I bind checkboxes this way, how do I later access to ID values from database that are selected (since I only set Content and I didn't set selectedValuePath or something like that)?
Here is my code below:
XML
<ListBox x:Name="grejanjeListBox" ItemsSource="{Binding}" DataContext="WinnerBazaDataSet" HorizontalAlignment="Left" Height="52" Margin="141,264,0,0" VerticalAlignment="Top" Width="307" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="grejanjeCheckBox" Content="{Binding NacinGrejanja}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Tip Objekta:" HorizontalAlignment="Left" Margin="30,323,0,0" VerticalAlignment="Top"/>
<ListBox x:Name="tipObjektaListBox" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="26" Margin="141,323,0,0" VerticalAlignment="Top" Width="307">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="tipObjektaCheckBox" Content="{Binding TipObjekta}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Opis Objekta:" HorizontalAlignment="Left" Margin="31,366,0,0" VerticalAlignment="Top"/>
<ListBox x:Name="opisObjektaListBox" ItemsSource ="{Binding}" HorizontalAlignment="Left" Height="52" Margin="142,366,0,0" VerticalAlignment="Top" Width="307">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="opisObjektaCheckBox" Content="{Binding OpisObjekta}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Dodatno:" HorizontalAlignment="Left" Margin="31,437,0,0" VerticalAlignment="Top"/>
<ListBox x:Name="dodatnoListBox" ItemsSource ="{Binding}" HorizontalAlignment="Left" Height="52" Margin="142,437,0,0" VerticalAlignment="Top" Width="307">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="dodatnoCheckBox" Content="{Binding Dodatno}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
C#
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
WinnerBazaDataSet wds = new WinnerBazaDataSet();
GrejanjeTableAdapter gta = new GrejanjeTableAdapter();
TipObjektaTableAdapter tta = new TipObjektaTableAdapter();
OpisObjektaTableAdapter ota = new OpisObjektaTableAdapter();
DodatnoTableAdapter dta = new DodatnoTableAdapter();
gta.Fill(wds.Grejanje);
tta.Fill(wds.TipObjekta);
ota.Fill(wds.OpisObjekta);
dta.Fill(wds.Dodatno);
this.DataContext = wds.Grejanje;
this.DataContext = wds.TipObjekta;
this.DataContext = wds.OpisObjekta;
this.DataContext = wds.Dodatno;
}
Aucun commentaire:
Enregistrer un commentaire