Я почти уверен, что поступаю неправильно, но любая помощь, чтобы подтолкнуть меня в правильном направлении, была бы очень признательна.
По сути, я пытаюсь добавить список пользовательских шрифтов, а затем отображать их в списке TextBlocks, но независимо от того, как много разных способов я пробую, я получаю эту ошибку, которая не делает много смысла для меня.
Ошибка: ошибка пути BindingExpression: свойство «FontFamilyList» не найдено в «Windows.UI.Xaml.Media.FontFamily». BindingExpression: Path = 'FontFamilyList' DataItem = 'Windows.UI.Xaml.Media.FontFamily'; целевым элементом является Windows.UI.Xaml.Controls.TextBlock '(Name =' FontSelector '); Свойство target - FontFamily (тип FontFamily)
Конечным результатом должно быть 24 текстовых блока подряд, каждый из которых содержит строку «abcdef», но каждый из них имеет свой шрифт.
Вот то, что я пробовал до сих пор.
Класс
public static class CustomFonts
{
public static FontFamily sketchy = new FontFamily("/Assets/font/a_bit_sketchy.ttf#sketchy");
public static FontFamily adam = new FontFamily("/Assets/font/adam.cg_pro.otf#adam");
public static FontFamily addled = new FontFamily("/Assets/font/addled.TTF#addled");
public static FontFamily adventure = new FontFamily("/Assets/font/adventure.ttf#adventure");
public static FontFamily agentorange = new FontFamily("/Assets/font/agentorange#agentorange");
public static FontFamily arial = new FontFamily("/Assets/font/arial.ttf#arial");
public static FontFamily bira = new FontFamily("/Assets/font/bira.ttf#bira");
public static FontFamily blueprint = new FontFamily("/Assets/font/blueprint.otf#blueprint");
public static FontFamily branbollFet = new FontFamily("/Assets/font/branbollFet.ttf#branbollFet");
public static FontFamily budmo = new FontFamily("/Assets/font/budmo_jiggler.otf#budmo");
public static FontFamily childs = new FontFamily("/Assets/font/childs.ttf#childs");
public static FontFamily collegiate = new FontFamily("/Assets/font/collegiate.ttf#collegiate");
public static FontFamily comesinhandy = new FontFamily("/Assets/font/comesinhandy.ttf#comesinhandy");
public static FontFamily dknanuk = new FontFamily("/Assets/font/dk_nanuk.otf#dknanuk");
public static FontFamily itcedscr = new FontFamily("/Assets/font/itcedscr.TTF#itcedscr");
public static FontFamily levi = new FontFamily("/Assets/font/levi_brush.TTF#levi");
public static FontFamily lobster = new FontFamily("/Assets/font/lobster.otf#lobster");
public static FontFamily missionscript = new FontFamily("/Assets/font/mission_script.otf#mission");
public static FontFamily moonbold = new FontFamily("/Assets/font/moon_bold.otfmoonbold");
public static FontFamily moonlight = new FontFamily("/Assets/font/moon_light.otf#moonlight");
public static FontFamily permanentmarker = new FontFamily("/Assets/font/permanentmarker.ttf#permanent");
public static FontFamily phosphate = new FontFamily("/Assets/font/phosphate.ttc#phosphate");
public static FontFamily ralewaydots = new FontFamily("/Assets/font/raleway_dots.ttf#raleway");
public static FontFamily rosewood = new FontFamily("/Assets/font/rosewood.otf#rosewood");
public static List<FontFamily> FontFamilyList;
public static List<FontFamily> PopulateFonts()
{
FontFamilyList = new List<FontFamily>
{
sketchy,
adam,
addled,
adventure,
agentorange,
arial,
bira,
blueprint,
branbollFet,
budmo,
childs,
collegiate,
comesinhandy,
dknanuk,
itcedscr,
levi,
lobster,
missionscript,
moonbold,
moonlight,
permanentmarker,
phosphate,
ralewaydots,
rosewood
};
return FontFamilyList;
}
}
Набор ItemsSource
public DesignView()
{
InitializeComponent();
FontList.ItemsSource = CustomFonts.PopulateFonts();
}
1024 * XAML *
<Grid Height="150" Margin="0,270,0,0">
<Image Source="ms-appx:///Resources/Elements/prev_250.png" Height="100" Width="100" HorizontalAlignment="Left"></Image>
<ListView Name="FontList" ItemsSource="{Binding CustomFonts}"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.IsHorizontalRailEnabled="True" VerticalAlignment="Center" HorizontalAlignment="Center"
Margin="100,270,100,20"
Height="70" AutomationProperties.SizeOfSet="24">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Bottom" Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Name="FontSelector" Text="abcdef" Grid.Column="0" Height="70" Width="70" Margin="1" VerticalAlignment="Center" FontFamily="{Binding FontFamilyList}">
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Image Source="ms-appx:///Resources/Elements/next_250.png" Height="100" Width="100" HorizontalAlignment="Right"></Image>
</Grid>