Click here to Skip to main content
15,877,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im trying to bind to System.Windows.Media.Fonts to make a combo box with font types

What I have tried:

HTML
<Grid>
   <Grid.DataContext>{x:Static Fonts.SystemFontFamilies}</Grid.DataContext>
        <ListBox>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock FontFamily="{Binding}" Text="{Binding}" FontSize="12"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
</Grid>
Posted
Updated 20-Jan-20 20:33pm

1 solution

You did not set the ItemsSource property.
Have a look at this:
<Window x:Class="WpfApp8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp8"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <ListBox ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock FontFamily="{Binding}" Text="{Binding}" FontSize="12"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900