简体   繁体   English

组合框填充了FontFamilies setSelectedItem

[英]Combobox filled with FontFamilies set SelectedItem

i have a problem: I want to make little Note Application for personal use. 我有一个问题:我想为个人使用做一些便笺申请。 In this little Scratchpad i have a settings menu with a combobox for all the installed Fonts. 在这个小小的Scratchpad中,我有一个带有所有已安装字体的组合框的设置菜单。

FontFamilyDrop.ItemsSource = Fonts.SystemFontFamilies; FontFamilyDrop.ItemsSource = Fonts.SystemFontFamilies;

Now i want to save and read this value in my settings.ini file. 现在,我想保存并在我的settings.ini文件中读取此值。 Writing the value works perfectly by converting the SelectedItem to a string. 通过将SelectedItem转换为字符串,可以完美地写入值。

When the user opens the settings menu, i want to preload the current font and i dont know how to set the SelectedItem property by just having a string for lets say "Lucida Console". 当用户打开设置菜单时,我想预加载当前字体,而我不知道如何仅通过让字符串说“ Lucida Console”来设置SelectedItem属性。

I've tried this one now: 我已经尝试过这个了:

for (int i = 2; i <= FontFamilyArray.GetLength(0); i++)
{
    Title = FontFamilyArray[i].ToString();
}

The problem is that it doesnt work. 问题是它不起作用。 It throws an exception. 它引发异常。

Now the thing that makes me confused is, that when i fill in "2" instead of i like this: 现在让我感到困惑的是,当我填写“ 2”而不是我这样时:

for (int i = 2; i <= FontFamilyArray.GetLength(0); i++)
{
    Title = FontFamilyArray[2].ToString();
}

This way it works perfectly... Does anyone know why? 这样,它就可以完美运作...有人知道为什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM