본문 바로가기

   
Programming/WPF

DataBinding, ImageViewer

반응형


<Window x:Class="WPFEx.DataBinding01"

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

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

        Title="DataBinding01" Height="300" Width="300">

       <StackPanel>

             <!--스크롤바의 값을 텍스트블럭에 표시-->

             <!--1. 버튼의 클릭 이벤트-->

             <TextBlock Name="txt1" />

             <ScrollBar Name="scroll1" Margin="10" Minimum="1" Maximum="100" SmallChange="1" LargeChange="10" Width="250" Orientation="Horizontal" />

             <Button Content="확인" Click="Button_Click" />

            

             <!--2. 스크롤바의 자체 이벤트-->

             <TextBlock Name="txt2" Margin="0, 20, 0, 0" />

             <ScrollBar Name="scroll2" Margin="10" Minimum="1" Maximum="100" SmallChange="1" LargeChange="10" Width="250" Orientation="Horizontal"

                              Scroll="scroll2_Scroll"/>

 

             <!--3. 데이터 바인딩(**): 바인딩이란 둘을 묶는다는 뜻-->

             <TextBlock Name="txt3" Margin="0, 20, 0, 0" Text="{Binding ElementName=scroll3, Path=Value}"/>

             <ScrollBar Name="scroll3" Margin="10" Minimum="1" Maximum="100" SmallChange="1" LargeChange="10" Width="250" Orientation="Horizontal"/>

            

            

       </StackPanel>

</Window>

 

 

  

<Window x:Class="WPFEx.DataBinding02"

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

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

        Title="DataBinding02" Height="300" Width="300">

       <StackPanel>

             <!--

                    데이터바인딩 모델

                    : 결합 방향에 따른 종류

                    1. 단방향(OneWay)

                           : 소스의 값을 참조하는 쪽만 변경O, 그 반대X

                    2. 양방향(TwoWay)

                           : 현재 기본값

                           : 양쪽 모두 변경이 되면 반영

                    3. 일회성(OneTime)

                           : 처음 한번만 바인딩이 되고 그 뒤는 반영X

             -->

             <!-- txt2 Text속성은 txt1 Text을 참고해서 값을 가지겠습니다. -->

             <TextBox Name="txt1" Text="기본값" />

             <TextBox Name="txt2" Text="{Binding ElementName=txt1, Path=Text}" />

 

 

             <ScrollBar Name="scroll1" Minimum="1" Maximum="100" Value="1" Orientation="Horizontal" />

 

             <!--Mode OneWay일 경우 참조쪽에서 값을 변경하고 난 뒤 바인딩이 풀려버리는 현상-->

             <ScrollBar Name="scroll2" Minimum="1" Maximum="100" Value="{Binding ElementName=scroll1,Path=Value,Mode=OneWay}" Orientation="Horizontal" />

 

       </StackPanel>

 

</Window>

 

 

 <Window x:Class="WPFEx.DataBinding03"

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

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

        Title="DataBinding03" Height="300" Width="300">

       <StackPanel HorizontalAlignment="Center">

 

             <ScrollBar Name="scroll1" Orientation="Horizontal" Minimum="-360" Maximum="360" Value="0" Width="250" Margin="10" />

             <ScrollBar Name="scroll2" Orientation="Horizontal" Minimum="1" Maximum="5" Value="1" Width="250" Margin="10" />

 

             <Button Content="버튼" Width="150" Height="150" Margin="30" RenderTransformOrigin="0.5,0.5">

                    <Button.RenderTransform>

                           <TransformGroup>

                                 <RotateTransform Angle="{Binding ElementName=scroll1,Path=Value}" />

                                 <ScaleTransform ScaleX="{Binding ElementName=scroll2,Path=Value}" ScaleY="{Binding ElementName=scroll2,Path=Value}" />

                           </TransformGroup>

                    </Button.RenderTransform>

             </Button>

 

       </StackPanel>

</Window>

 





이미지 뷰어 


 <Window x:Class="WPFEx.MiniProject"

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

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

        Title="MiniProject" Height="600" Width="800">

       <Window.Resources>

             <!--붓 객체 등록-->

             <SolidColorBrush x:Key="bBrush" Color="Black" />

             <LinearGradientBrush x:Key="lBrush" StartPoint="0,0" EndPoint="0,1">

                    <GradientStop Offset="0" Color="Gray" />

                    <GradientStop Offset="0.3" Color="#FF222222" />

                    <GradientStop Offset="0.3" Color="Black" />

                    <GradientStop Offset="0.9" Color="Black" />

                    <GradientStop Offset="0.9" Color="#FF222222" />

                    <GradientStop Offset="1" Color="Gray" />

             </LinearGradientBrush>

 

             <!--변형객체 : 셀프 바인딩(자신의 속성을 자신의 다른 속성과 바인딩 하는 기술-->

             <ScaleTransform x:Key="sTrans" ScaleX="3" ScaleY="{Binding RelativeSource={RelativeSource Self}, Path=ScaleX}" />

       </Window.Resources>

 

       <Grid ShowGridLines="False">

             <Grid.RowDefinitions>

                    <RowDefinition Height="50" />

                    <RowDefinition Height="*" />

                    <RowDefinition Height="50" />

             </Grid.RowDefinitions>

             <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="70" />

                    <ColumnDefinition Width="*" />

             </Grid.ColumnDefinitions>

 

             <Grid.Children>

                    <!--위 아래 사각형-->

                    <Rectangle Grid.Row="0" Grid.Column="0" Fill="{StaticResource lBrush}" Grid.ColumnSpan="2" />

                    <Rectangle Grid.Row="2" Grid.Column="0" Fill="{StaticResource lBrush}" Grid.ColumnSpan="2" />

 

                    <!--왼쪽 슬라이더(TrackBar)-->

                    <Slider Orientation="Vertical" Minimum="1" Maximum="10" Margin="20" Height="200" Name="slider1" Grid.Row="1" Grid.Column="0" Value="{Binding Source={StaticResource sTrans}, Path=ScaleX, Mode=TwoWay}" />

 

                    <!--가운데 이미지 리스트 => ListBox-->

                    <!--ScrollViewer . HorizontalScrollBarVisibility : ListBox가 기본적으로 생기는 스크롤바를 없애기 -->

                    <ListBox Name="imgList" Background="AliceBlue" Grid.Row="1" Grid.Column="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">

                           <!--<ListBox.Items>

                                 <TextBlock Text="aaa" />

                                 <TextBlock Text="bbb" />

                                 <TextBlock Text="ccc" />

                           </ListBox.Items>-->

 

                           <!--리스트 박스 : 스택패널 => WrapPanel-->

                           <ListBox.ItemsPanel>

                                 <ItemsPanelTemplate>

                                        <WrapPanel />

                                 </ItemsPanelTemplate>

                           </ListBox.ItemsPanel>

 

                           <ListBox.Items>

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\01.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\02.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\03.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\04.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\05.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\06.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\07.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\08.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\09.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\10.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\11.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\12.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\13.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\14.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                                 <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\15.jpg" Height="35" Margin="3,8" LayoutTransform="{StaticResource sTrans}" />

                           </ListBox.Items>

                    </ListBox>

             </Grid.Children>

 

       </Grid>

 

</Window>

 

 

반응형