본문 바로가기

   
Programming/WPF

Code, Greed, Resource

반응형

Code


Code Xaml
 
<
Application x:Class="WPFEx.App"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             StartupUri="Code.xaml">

    <Application.Resources>

        

    </Application.Resources>

</Application>
 

Code 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.Shapes;

 

namespace WPFEx

{

       /// <summary>

       /// Code.xaml에 대한 상호 작용 논리

       /// </summary>

       public partial class Code : Window

       {

             public Code()

             {

                    InitializeComponent();

             }

 

             private void Button_Click(object sender, RoutedEventArgs e)

             {

                    Button btn = new Button();

                    btn.Width = 50;

                    btn.Height = 50;

                    btn.Content = "추가됨";

 

                    //<Button Canvas.Left="10" Canvas.Top="20"

 

                    //**복합 속성을 C#에서 접근하는 방법

 

                    //1. 복합 속성을 보유하고 있는 클래스를 통해서..

                    //Canvas.SetLeft(btn, 100);//Canvas.Left="100"

                    //Canvas.SetTop(btn, 100);//Canvas.Top="100"

 

                    //2. 버튼 객체를 통해서..

                    //DependencyProperty(의존 속성) - 애니메이션

                    // - 객체 상태에 대한 추상적인 정의

                    btn.SetValue(Canvas.LeftProperty, (double)100);

                    btn.SetValue(Canvas.TopProperty, (double)100);

 

                    btn.SetValue(Button.WidthProperty, (double)200);

                    //btn.Width = 200;

 

                    //btn.SetValue(btn.Width, (double)200);

 

                    canvas1.Children.Add(btn);

             }

       }

}

 

Greed



Greed Xaml
 <Window x:Class="WpfEx.Ex10_Grid"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Ex10_Grid" Height="300" Width="300">

   

       <!--<Grid>

             <Grid.Children>

                    <Button Background="Yellow">버튼1</Button>

                    <Button Background="Red" Width="100" Height="100">버튼2</Button>

                    <Button Width="50" Height="50">버튼3</Button>

             </Grid.Children>

       </Grid>-->

      

       <!--<Grid>

             <Grid.Children>

                    <Button Margin="50, 10, 100, 0">버튼</Button>

             </Grid.Children>

       </Grid>-->

      

       <!--<Grid>

             <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="48,62,0,0" Name="button1" VerticalAlignment="Top" Width="75" />

       </Grid>-->

      

       <!--<Grid>

             <Button Width="50" Height="50" Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">버튼1</Button>

             <Button Width="50" Height="50" Margin="150,150,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">버튼2</Button>

       </Grid>-->

      

       <Grid ShowGridLines="True">

             <!--표형식 : 2x2-->

             <Grid.RowDefinitions>

                    <RowDefinition Height="50" /> <!--행하나-->

                    <RowDefinition Height="*" />

             </Grid.RowDefinitions>

             <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="50" /> <!--열하나-->

                    <ColumnDefinition Width="*" />

             </Grid.ColumnDefinitions>

             <Grid.Children>

                    <!--Grid.Row : 복합속성, 종속속성 -->

                    <Button Grid.Row="0" Grid.Column="0" Click="Button_Click">1</Button>

                    <Button Grid.Row="0" Grid.Column="1" Name="btn2">2</Button>

                    <Button Grid.Row="1" Grid.Column="0">3</Button>

                    <!--<Button Grid.Row="1" Grid.Column="1">4</Button>-->

             </Grid.Children>

       </Grid>

      

</Window>

 

 

Greed 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.Shapes;

 

namespace WpfEx

{

       /// <summary>

       /// Ex10_Grid.xaml에 대한 상호 작용 논리

       /// </summary>

       public partial class Ex10_Grid : Window

       {

             public Ex10_Grid()

             {

                    InitializeComponent();

             }

 

             private void Button_Click(object sender, RoutedEventArgs e)

             {

                    //<Button Grid.Row="0" Grid.Column="1" Name="btn2">2</Button>

 

                    //1.

                    //Grid.SetRow(btn2, 1);//쓰기

                    //Grid.GetRow(btn2);//읽기

 

                    //2.

                    btn2.SetValue(Grid.RowProperty, 1);

                    //btn2.GetValue(Grid.RowProperty);

             }

       }

}

 

Resource


Resource Xaml

<Window x:Class="WPFEx.Resources"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Resources" Height="300" Width="300">

       <Window.Resources>

             <!--리소스를 선언할 수 있는 공간-->

             <SolidColorBrush x:Key="brush1" Color="Crimson" />

       </Window.Resources>

       <StackPanel>

             <StackPanel.Resources>

                   

             </StackPanel.Resources>

             <StackPanel.Children>

                    <!--요구사항 : 노란색 x 3-->

                    <!--<Button Content="버튼" Width="150" Height="50" Margin="5" Background="Yellow"></Button>

                    <Button Content="버튼" Width="150" Height="50" Margin="5" Background="Yellow"></Button>

                    <Button Content="버튼" Width="150" Height="50" Margin="5" Background="Yellow"></Button>

                    <Button></Button>-->

                   

                    <!--<Button Content="버튼" Width="150" Height="50" Margin="5" Background="{StaticResource ResourceKey=brush1}"></Button>-->

                    <Button Content="버튼" Width="150" Height="50" Margin="5" Background="{StaticResource brush1}"></Button>

                    <Button Content="버튼" Width="150" Height="50" Margin="5" Background="{StaticResource brush1}"></Button>

                    <Button Content="버튼" Width="150" Height="50" Margin="5" Background="{StaticResource brush1}"></Button>

             </StackPanel.Children>

       </StackPanel>

      

</Window>

<!--

       리소스 : 반복해서 사용되는 (외부) 자원

       1. 일반 객체

       2. 스타일 *****

       3. 템플릿

      

       기본타입이 아닌것만 리소스화 가능

-->

  
 

<Window x:Class="WPFEx.Resources02"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Resources02" Height="300" Width="300">

       <StackPanel>

             <StackPanel.Resources>

                    <SolidColorBrush x:Key="yellowBrush" Color="Yellow" />

             </StackPanel.Resources>

             <Button Content="버튼" Width="150" Height="50" Background="{StaticResource yellowBrush}" />

             <Button Content="버튼" Width="150" Height="50" Background="{StaticResource yellowBrush}" />

             <Button Content="버튼" Width="150" Height="50" Background="{StaticResource yellowBrush}" />

             <Button Content="버튼" Width="150" Height="50" Background="{StaticResource yellowBrush}" />

       </StackPanel>

</Window>

<!--

       1. 리소스 : 재사용 가능한 자원

       2. 내장형 데이터 불가능(숫자, 문자열..)

       3. 객체가 가능(SolidColorBrush..)

-->

  

반응형