Редагувати

Поділитися через


Fonts.GetFontFamilies Method

Definition

Returns the collection of FontFamily objects from a specified font location.

Overloads

GetFontFamilies(String)

Returns the collection of FontFamily objects from a string value that represents the location of the fonts.

GetFontFamilies(Uri)

Returns a collection of FontFamily objects from a uniform resource identifier (URI) value that represents the location of the fonts.

GetFontFamilies(Uri, String)

Returns a collection of FontFamily objects using a base uniform resource identifier (URI) value to resolve the font location.

GetFontFamilies(String)

Returns the collection of FontFamily objects from a string value that represents the location of the fonts.

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(System::String ^ location);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (string location);
static member GetFontFamilies : string -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (location As String) As ICollection(Of FontFamily)

Parameters

location
String

The location that contains the fonts.

Returns

An ICollection<T> of FontFamily objects that represent the fonts in location.

Exceptions

The location is null. You cannot pass null, because this parameter is treated as a path or URI.

Examples

The following example shows how to use this method to return the collection of FontFamily objects from a font location.

// Return the font family collection for the selected directory location.
System.Collections.Generic.ICollection<FontFamily> fontFamilies = Fonts.GetFontFamilies("C:/MyFonts");

// Enumerate through the font family collection.
foreach (FontFamily fontFamily in fontFamilies)
{
    // Separate the URI directory source info from the font family name.
    string[] familyName = fontFamily.Source.Split('#');

    // Add the font family name to the fonts combo box.
    comboBoxFonts.Items.Add(familyName[familyName.Length - 1]);
}

comboBoxFonts.SelectedIndex = 0;
' Return the font family collection for the selected directory location.
Dim fontFamilies As System.Collections.Generic.ICollection(Of FontFamily) = Fonts.GetFontFamilies("C:/MyFonts")

' Enumerate through the font family collection.
For Each fontFamily As FontFamily In fontFamilies
    ' Separate the URI directory source info from the font family name.
    Dim familyName() As String = fontFamily.Source.Split("#"c)

    ' Add the font family name to the fonts combo box.
    comboBoxFonts.Items.Add(familyName(familyName.Length - 1))
Next fontFamily

comboBoxFonts.SelectedIndex = 0

Applies to

GetFontFamilies(Uri)

Returns a collection of FontFamily objects from a uniform resource identifier (URI) value that represents the location of the fonts.

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(Uri ^ baseUri);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (Uri baseUri);
static member GetFontFamilies : Uri -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (baseUri As Uri) As ICollection(Of FontFamily)

Parameters

baseUri
Uri

The base URI value of the location of the fonts.

Returns

An ICollection<T> of FontFamily objects that represent the fonts in baseUri.

Examples

The following example shows how to use this method to return the collection of FontFamily objects from a base URI location.

foreach (FontFamily fontFamily in Fonts.GetFontFamilies("file:///D:/MyFonts/"))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies("file:///D:/MyFonts/")
    ' Perform action.
Next fontFamily

To return the collection of FontFamily objects in an application's resources, use the "pack://application" URI notation shown in the following example.

foreach (FontFamily fontFamily in Fonts.GetFontFamilies(new Uri("pack://application:,,,/")))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies(New Uri("pack://application:,,,/"))
    ' Perform action.
Next fontFamily

Applies to

GetFontFamilies(Uri, String)

Returns a collection of FontFamily objects using a base uniform resource identifier (URI) value to resolve the font location.

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(Uri ^ baseUri, System::String ^ location);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (Uri baseUri, string location);
static member GetFontFamilies : Uri * string -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (baseUri As Uri, location As String) As ICollection(Of FontFamily)

Parameters

baseUri
Uri

The base URI value of the location of the fonts.

location
String

The location that contains the fonts.

Returns

An ICollection<T> of FontFamily objects that represent the fonts in the resolved font location.

Examples

The following example shows how to use this method to return the collection of FontFamily objects from the resolved font location. In this case, the application contains a subdirectory named "resources".

foreach (FontFamily fontFamily in Fonts.GetFontFamilies(new Uri("pack://application:,,,/"), "./resources/"))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies(New Uri("pack://application:,,,/"), "./resources/")
    ' Perform action.
Next fontFamily

Applies to