Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Checkbox content not correct

Tags:

c#

wpf

xaml

My problem is my checkbox content doesnt display underscores or the & symbol. I've read about the RecognizeAccessKey attribute, but i can't get it working. My listbox looks like this:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
         ItemsSource="{Binding Channels}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <ContentPresenter RecognizesAccessKey="False">
                <CheckBox Content="{Binding Item}"
                          IsChecked="{Binding IsChecked}"
                          Width="149"
                          MinWidth="149" />
            </ContentPresenter>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

Can anybody tell me how to get this fixed, so my Checkbox's content will display underscores and & symbols?

thank you very much!

like image 811
user3596113 Avatar asked Aug 14 '14 14:08

user3596113


1 Answers

You could use TextBlock as CheckBox.Content, instead of binding it directly, and bind its Text property

<CheckBox IsChecked="{Binding IsChecked}" Width="149" MinWidth="149">
   <CheckBox.Content>
      <TextBlock Text="{Binding Item}"/>
   </CheckBox.Content>
</CheckBox>

By default CheckBox will wrap TextBlock in AccessText when it displays Content

like image 149
dkozl Avatar answered Sep 19 '22 00:09

dkozl