July 14, 2022
리소스
01.교육내용
01.1 x로 시작하는것
01.2 코드로 xaml로 만들기
01.3 exe 이외에 있는곳
01.4 라이브러리
01.5 과제
02.공부내용
02.1 Resources적용해보기
02.2 cs코드 xmal로 변경해보기
03.과제
03.1 WPF Library 적용해서 다른 프로젝트에서 사용해보기
02.3 리소스 관리를 위한 폴더 생성
02.3 프로젝트 참조 걸기
02.3 해당 프로젝트의 App.xaml에 추가
02.4 Resource 적용해보기
x.name, x.key
<Window.Resources>
<Style TargetType ={x:Type Button} x:Key ="Hi">
<Setter Property="Background" Value="Blue"/>
</Style>
</Window.Resources>
<!-- <Button Style="{StaticResource Hi}"> -->
<Button Style="{StaticResource ResourceKey=Hi}">
Button1
</Button>
add
<Button Background ="{StaticResource background}">
</Button>
실습 진행
window는 컨트롤 하나만 가짐
그 오류 해결하는 법
<StackPanel Name ="sp">
<StackPanel.Resource>
<SolidColorBrush x:Key ="background" Color=:"Auqa"/>
</StackPanel.Resource>
<Button Name ="btn1">Button1</Button>
<Button Name ="btn2">Button2</Button>
<Button Name ="btn3" Background ="{StaticResource background}">Button3</Button>
</StackPanel>
라이브러리?
<Window.Resources>
<Style TargetType="{x:Type Button}" x:Key ="Hi">
<Setter Property="Background" Value="#FFFF3A00"/>
<Setter Property="FontSize" Value="30"/>
</Style>
</Window.Resources>
<StackPanel>
<StackPanel.Resources>
<SolidColorBrush x:Key="background" Color="Blue"/>
</StackPanel.Resources>
<Button Background="{StaticResource background}">Button 1</Button>
<Button Background="{StaticResource background}">Button 2</Button>
<Button Style="{StaticResource Hi}">Button 3</Button>
</StackPanel>
xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SolidColorBrush silverBrush = Brushes.Silver;
App application = (App)Application.Current;
application.Resources.Add("background", silverBrush);
btn1.Background = (SolidColorBrush)btn1.FindResource("background");
}
}
xaml로 변경
<Application.Resources>
<SolidColorBrush x:Key = "app1" Color =" Blue"/>
</Application.Resources>
<Window.Resources>
<Style TargetType="{x:Type Button}" x:Key ="Hi">
<Setter Property="Background" Value="#FFFF3A00"/>
<Setter Property="FontSize" Value="30"/>
</Style>
</Window.Resources>
<StackPanel>
<StackPanel.Resources>
<SolidColorBrush x:Key="background" Color="Gray"/>
</StackPanel.Resources>
<Button Background="{StaticResource background}">Button 1</Button>
<Button Background="{StaticResource app1}">Button 2</Button>
<Button Style="{StaticResource Hi}">Button 3</Button>
</StackPanel>
before
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>
after
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="app1" Color="blue"/>
</ResourceDictionary>
before
<Application x:Class="WpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
after
<Application x:Class="WpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Wpf.ControlLibrary;component/Resources/Styles/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
before
after