KeiStory

WPF Font 적용하기

 

사용하고자 할 Font 파일을 다운로드합니다.

프로젝트에 Fonts 폴더를 만들고 다운로드한 폰트파일을 추가합니다.

폰트의 속성창에서 아래처럼 리소스(Resource)를 선택해 줍니다.


화면의 xaml 단에 아래처럼 정의해서 쓰면 됩니다.

FontFamily="/Wpf.FontTest;component/Fonts/#Donoun"

<Window x:Class="Wpf.FontTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="/Wpf.FontTest;component/Fonts/#Donoun"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <StackPanel>
        <Label  Content="다람쥐 헌 쳇바퀴에 타고파. 폰트 적용 예제(Donoun - 전체적용)" FontSize="25" />
        <TextBlock Text="다람쥐 헌 쳇바퀴에 타고파. 폰트 적용 예제(Noto Sans)" FontSize="25" FontFamily="/Wpf.FontTest;component/Fonts/#Noto Sans CJK KR"/>
        <TextBox   Text="다람쥐 헌 쳇바퀴에 타고파. 폰트 적용 예제(고딕)" FontSize="25" FontFamily="고딕"/>
        <Label  Content="다람쥐 헌 쳇바퀴에 타고파. 폰트 적용 예제(Donoun - 전체적용)" FontSize="25" />
    </StackPanel>
</Window>

결과

 

여기서 중요한 건 폰트명에 #을 붙이고 폰트 파일명을 넣는 게 아니라 폰트이름을 넣어야 하는데

이는 글꼴을 클릭하면 아래와 같은 창에서 글꼴 이름을 넣어줘야 합니다.

그런데 아래처럼 간혹 글꼴이름이 한글로 나올 때가 있는데

이때는 아래 코드를 통해 영어 명칭을 알아내 영어 명칭으로 넣어주어야 합니다.

/// <summary>
/// 설치된 글꼴 명칭 확인
/// </summary>
private void FontList()
{
    List<string> fontList = new List<string>();
    foreach (FontFamily font in Fonts.SystemFontFamilies)
    {
        fontList.Add(string.Join(",", font.FamilyNames.Values));
        Debug.WriteLine(string.Join(",", font.FamilyNames.Values));
    }
}

 

소스
https://github.com/kei-soft/KJunBlog/tree/master/Wpf.FontTest

 

KJunBlog/Wpf.FontTest at master · kei-soft/KJunBlog

Contribute to kei-soft/KJunBlog development by creating an account on GitHub.

github.com

 

반응형

'코딩 > WPF' 카테고리의 다른 글

WPF Popup Drag Move 처리하기  (0) 2024.10.07
WPF Parent Binding  (0) 2024.10.06
WPF Freezable  (1) 2024.09.27
WPF GraphicsPath 를 PathGeometry 로 변환하기  (0) 2024.09.23
WPF Image Zoom 및 Panning 처리하기  (0) 2024.09.23

공유하기

facebook twitter kakaoTalk kakaostory naver band