WPF 의 정적 자원 과 동적 자원
http://hi.baidu.com/wangjunwangjuna/blog/item/c9dd3e4e9c1209dad1c86a91.html
먼저 정적 자원 과 동적 자원 의 예 시 를 살 펴 보 겠 습 니 다. 코드 는 다음 과 같 습 니 다.
XAML 코드 는 다음 과 같 습 니 다.
<Window x:Class="WPF .Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ImageBrush x:Key="MyBrush"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0 0 30 30"
ImageSource="/image/1.png"
Opacity="0.9"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Name="btn_Message" Grid.Row="0" Background="{StaticResource MyBrush}">1111111111</Button>
<Button Grid.Row="1" Click="Button_Click">222222222222</Button>
<Button Grid.Row="2" Background="{DynamicResource MyBrush}">33333333</Button>
</Grid>
</Window>
CS 코드 는 다음 과 같 습 니 다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF
{
/// <summary>
/// Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Resources["MyBrush"] = new LinearGradientBrush(new GradientStopCollection()
{
new GradientStop()
{
Color=Colors.Red,
Offset=0.1
},
new GradientStop()
{
Color=Colors.Green,
Offset=0.5
},
new GradientStop()
{
Color=Colors.Blue,
Offset=0.9
}
});
}
}
}
위의 예제 에서 볼 수 있 듯 이 두 번 째 단 추 를 누 르 면 자원 의 이미지 브러시 를 Linear 브러시 로 변경 합 니 다. 이때 동적 자원 은 이에 따라 바 뀌 고 정적 자원 은 바 뀌 지 않 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.