C#/C# WPF

Constant for Xaml

doublerabbits 2022. 7. 16. 13:08

1. xaml 파일 상단에 아래 내용 추가

xmlns:sys="clr-namespace:System;assembly=mscorlib"

 

2. 상수 선언

<sys:Int32 x:Key="One">1</sys:Int32>
<sys:Int32 x:Key="Two">2</sys:Int32>
<sys:Int32 x:Key="Three">3</sys:Int32>

 

 

예제

<Window x:Class="MCP_Starter.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://prismlibrary.com/"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        prism:ViewModelLocator.AutoWireViewModel="True"
        WindowStyle="None"
        ResizeMode="NoResize"
        Background="Black"
        Height="400" Width="380">
    <Window.Resources>
        <ResourceDictionary>
            <sys:Int32 x:Key="One">1</sys:Int32>
            <sys:Int32 x:Key="Two">2</sys:Int32>
            <sys:Int32 x:Key="Three">3</sys:Int32>
        </ResourceDictionary>
    </Window.Resources>

	...

</Window>