Author Topic: WPF Checkbox Content  (Read 1430 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
WPF Checkbox Content
« on: February 06, 2021, 08:51:25 PM »
I am still working on converting some Winforms to WPF Windows. I have one that is working perfectly, except for one, very annoying, issue. Here's a snip of the XAML to create a CheckedListBox:
Code - XML: [Select]
  1.             <ListBox x:Name="clb_PtGrps"  ItemsSource="{Binding PresentationObjects}" >
  2.                 <ListBox.ItemTemplate>
  3.                     <HierarchicalDataTemplate>
  4.                         <CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" HorizontalAlignment="Left"/>
  5.                     </HierarchicalDataTemplate>
  6.                 </ListBox.ItemTemplate>
  7.                 <ListBox.ToolTip>
  8.                     <ToolTip>
  9.                         <TextBlock Text="Checked groups will be placed at the top in the same relative order. All others will be sorted."
  10.                                   TextWrapping="WrapWithOverflow" Width="200"/>
  11.                     </ToolTip>
  12.                 </ListBox.ToolTip>
  13.             </ListBox>
  14.  

Which works almost perfectly. The issue is that I have one object with a name having a leading Underscore, such as "_AllPoints". When that item is placed into the checkbox Content, the underscore is placed UNDER the A instead of showing "_A". The same list, when used in a Winforms CheckedListBox Text property display correctly. So, how in the world do I get the Content to display as it should?

HAH! Just before I posted this I had a fleeting thought and solved this on my own.  :lol: For anyone stumbling across this, here is the change I made to get this to work:
Code - XML: [Select]
  1.                         <CheckBox  IsChecked="{Binding IsChecked}" HorizontalAlignment="Left">
  2.                             <StackPanel>
  3.                                 <TextBlock Text="{Binding Name}"/>
  4.                             </StackPanel>
  5.                         </CheckBox>
  6.