-1

I'm working on a project to extract Adobe Creative Cloud fonts to another directory so they can be used in external programs that don't recognize them. I would like to populate an Extended WPF Toolkit CheckListBox with the names of the fonts I've scraped from the Adobe directory. However, I've created a custom class to hold the data I need. It's a little hard to explain without the code so here goes.

// custom Font class
public class Font
{
    public string FontName { get; set; }
    public string FontPath { get; set; }
    public bool IsChecked { get; set; }
}

// list of fonts to be bound to the CheckListBox
public List<Font> fontItems;

// function that appends items to the list
private void retrieveFonts_Click(object sender, RoutedEventArgs e)
{
    ...
    Font font = new Font
    {
        FontName = fontName,
        FontPath = fontPath,
        IsChecked = true
    }
    fontItems.Add(font)
}
<!--CheckListBox with my best guess for the binding-->
<xctk:CheckListBox
    Name="listFontBox"
    Grid.Row="0"
    IsSelectAllActive="False"
    ItemsSource="{Binding fontItems.FontName}">
</xctk:CheckListBox>

I've tried looking at threads on SO and on other external websites and none of the code seems to work on modern day WPF.

How can I get the CheckBoxList to populate with a list of all the FontName properties of the Font objects? Is this possible at all?

Justin Jung
  • 27
  • 2
  • 8

1 Answers1

0

First binding generally doesn't work to fields. Change the fontItems field to property. If you want to populate your list better way is to use ObservableCollection.

public ObservableCollection<Font> fontItems { get;set; } 

Bind it to CheckListBox and set DisplayMemberPath.

<xctk:CheckListBox DisplayMemberPath="FontName"
                   Grid.Row="0"
                   SelectedMemberPath="IsChecked"
                   IsSelectAllActive="False"
                   ItemSource="{Binding fontItems}" />
puko
  • 2,819
  • 4
  • 18
  • 27