lundi 15 février 2021

c# wpf in a listbox doing binding with checkbox to an object within another object

I have a Listbox which consists of elements that looks like this.

 class ItemForListbox
    {
        public string path { get; set; }
        public string file { get; set; }
        public InstallationPackageChoice choices { get; set; }
        public KeepKill keepKill { get; set; }
    }

The choices and keepKill are objects.

My XAML for the listbox has this DataTemplate

<ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                        <Button Name="btnPackageVersion" Style="{StaticResource ListBoxButtonFormat}" Content ="Package version" Click="btnInstallPackage_Click" HorizontalAlignment="Right"/>

                        <TextBlock Name="txtBlkPath" Text="{Binding path}" FontSize="10" Width="500" Height="20" Margin="10,10,0,0"/>
                        <Button Name="btnFilterPath" Style="{StaticResource ListBoxButtonFormat}" Content ="Filter path" Click="btnFilterpath_Click" HorizontalAlignment="Right"/>

                        <TextBlock Name="txtBlkFile" Text="{Binding file}" FontSize="10" Width="150" Height="20" Margin="10,10,0,0"/>
                        <Button Name="btnFilterfile" Style="{StaticResource ListBoxButtonFormat}" Content="Filter file" Click="btnFilterfile_Click" HorizontalAlignment="Right"/>

                        <CheckBox Name="chkBxKeep" Content="Keep" VerticalAlignment="Center" HorizontalAlignment="Right" IsChecked="True" Checked="chkBxKeep_Checked"/>
                        <CheckBox Name="chkBxKill" Content="Kill" VerticalAlignment="Center" HorizontalAlignment="Right" Checked="chkBxKill_Checked"/>

                        <Separator  Name="MySeparator" 
                                        Height="3"
                                        Width="Auto"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Bottom"                   
                                        Background="Red" />
                    </StackPanel>
                </DataTemplate>
</ItemsControl.ItemTemplate>

The two checkboxes underlying data is the killKeep object in the Listbox element object.

The problem is that i would like to have a radiobutton functionality of the two checkboxes, so when i check a checkbox, the other one unchecks. The reason i dont use radiobuttons are that i simply do not understand them in regards to binding. But now i find i also do not know how to do this binding with the checkboxes.

I hope someone can help me.




Aucun commentaire:

Enregistrer un commentaire