samedi 19 mai 2018

How to make label on the same level as checkbox, but not toggle on label click in WPF?

I want to make checkbox list which toggles only if directly clicked on checkbox.

Unfortunately if I make this way:

                    <ListBox Name="LanguagesListBox">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <ListBoxItem>
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox/>
                                        <Label Content="{Binding InputLanguage.LayoutName}"/>
                                    </StackPanel>

                                </ListBoxItem>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

I get checkbox not vertially aligned with it's label:

enter image description here

But if I write

                  <ListBox Name="LanguagesListBox">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <ListBoxItem>
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox Content="{Binding InputLanguage.LayoutName}"/>

                                    </StackPanel>

                                </ListBoxItem>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

I get checkbox toggle if clicked at the label

enter image description here

How to get both?




Aucun commentaire:

Enregistrer un commentaire