블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
반응형

Category

Recent Post

Recent Comment

Archive

2010. 5. 21. 01:54 .Net Project/WPF
반응형
1. 화면 UI 구성 - > Page 폴더 생성 ->
2. 위의 내용 .Xaml 파일을 추가  하도록 한다

3. 화면 디자인 구성
3 - 1 DescriptionPage

<Page x:Class="PatientReferrals.Pages.DescriptionPage"

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

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

      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

      mc:Ignorable="d"

      d:DesignHeight="300" d:DesignWidth="300"

                  Title="Description" Width="400" WindowTitle="Referral Description">

    <Page.CommandBindings>

        <CommandBinding Command="Open" Executed="open_Executed" />

        <CommandBinding Command="Save" Executed="save_Executed" />

        <CommandBinding Command="NextPage"

            CanExecute="CommandBinding_CanExecute"  

            Executed="CommandBinding_Executed" />

    </Page.CommandBindings>

    <DockPanel Margin="5">

        <Menu DockPanel.Dock="Top">

            <MenuItem Header="File">

                <MenuItem Command="Open" Header="_Open" />

                <MenuItem Command="Save" Header="_Save" />

            </MenuItem>

            <MenuItem Header="Edit">

                <MenuItem Command="Cut" Header="_Cut" />

                <MenuItem Command="Copy" Header="C_opy" />

                <MenuItem Command="Paste" Header="_Paste" />

            </MenuItem>

        </Menu>

        <ToolBarTray DockPanel.Dock="Top">

            <ToolBar>

                <Button Command="Open" Content="Open" />

                <Button Command="Save" Content="Save" />

            </ToolBar>

            <ToolBar>

                <Button Command="Cut" Content="Cut" />

                <Button Command="Copy" Content="Copy" />

                <Button Command="Paste" Content="Paste" />

            </ToolBar>

        </ToolBarTray>

        <StackPanel>

            <TextBox x:Name="description" Height="300" SpellCheck.IsEnabled="True"

                TextWrapping="Wrap" VerticalAlignment="Top" />

            <Button x:Name="nextPage" Command="{x:Static NavigationCommands.NextPage}"

                Content="" HorizontalAlignment="Right" Margin="0,10,0,0" Width="60" />

        </StackPanel>

    </DockPanel>

</Page> 




3 - 2  DetailsPage

<Page x:Class="PatientReferrals.Pages.DetailsPage"

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

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

      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

      mc:Ignorable="d"

      d:DesignHeight="300" d:DesignWidth="300"

                  Title="상세보기" Width="400" WindowTitle="Referral Details">

    <Page.CommandBindings>

        <CommandBinding Command="NextPage" CanExecute="CommandBinding_CanExecute"

            Executed="CommandBinding_Executed"></CommandBinding>   

    </Page.CommandBindings>

   

<StackPanel Margin="10">   

        <Grid>

            <Grid.ColumnDefinitions>

                <ColumnDefinition />

                <ColumnDefinition Width="Auto" />

            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

            </Grid.RowDefinitions>

 

            <TextBlock FontWeight="Bold" Grid.Column="0" Grid.Row="0" Margin="0,10,0,0"

                Text="Patient Name:" />

            <TextBox x:Name="patientName" Grid.Column="0" Grid.Row="1" Margin="0,0,5,0" />

            <Button x:Name="patientSearch" Content="Search" Grid.Column="1" Grid.Row="1"

                Width="60" Click="patientSearch_Click" />           

            <TextBlock FontWeight="Bold" Grid.Column="0" Grid.Row="2" Margin="0,10,0,0"

                Text="Search Results:" />

            <ListBox x:Name="patientResults" Grid.Column="0" Grid.ColumnSpan="2"

                Grid.Row="3" MinHeight="50" />

 

            <TextBlock FontWeight="Bold"

                       Grid.Column="0"

                       Grid.Row="4"

                       Margin="0,10,0,0"

                       Text="Specialist Name:" />

            <TextBox x:Name="specialistName"

                     Grid.Column="0"

                     Grid.Row="5"

                     Margin="0,0,5,0" />

            <Button x:Name="specialistSearch"

                    Content="Search"

                    Grid.Column="1"

                    Grid.Row="5"

                    Width="60" Click="specialistSearch_Click" />

            <TextBlock FontWeight="Bold"

                       Grid.Column="0"

                       Grid.Row="6"

                       Margin="0,10,0,0"

                       Text="Search Results:" />

            <ListBox x:Name="specialistResults"

                     Grid.Column="0"

                     Grid.ColumnSpan="2"

                     Grid.Row="7"

                     MinHeight="50" /> 

        </Grid> 

        <Button x:Name="next" Command="NextPage" Content="다음" HorizontalAlignment="Right"

            Margin="0,10,0,0" Width="60" /> 

    </StackPanel>

</Page> 


3 - 3 Summary Page

<Page x:Class="PatientReferrals.Pages.SummaryPage"

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

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

    Loaded="Page_Loaded"

    Title="Summary"

    WindowTitle="Referrals Summary"

    Width="400">

 

    <StackPanel Margin="5">

 

        <TextBlock Style="{DynamicResource label}"

                   Text="Patient Name:" />

        <Label x:Name="patientName"

               Margin="10, 0, 0, 0"

               Content="{Binding}" />

        <TextBlock Style="{DynamicResource label}" 

                   Text="Specialist Name:" />

        <Label x:Name="specialistName"

               Margin="10, 0, 0, 0"

               Content="{Binding}" />

        <TextBlock Style="{DynamicResource label}" 

                   Text="Description:" />

        <TextBlock x:Name="descripiton"

                   Margin="12, 0, 0, 0"

                   Text="{Binding}"

                   TextWrapping="Wrap" />

 

        <StackPanel HorizontalAlignment="Right"

                    Orientation="Horizontal">

            <Button x:Name="send"

                    Click="send_Click"

                    Content="Send"

                    Margin="0, 0, 5, 0"

                    Width="60" />

            <Button x:Name="cancel"

                    Click="cancel_Click"

                    Content="Cancel"

                    Width="60" />

        </StackPanel>       

    </StackPanel>

</Page> 


4. F7 번을 클릭하여 코드 비하인드 페이지 작성

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;

using System.IO; //

using Microsoft.Win32; //

 

namespace PatientReferrals.Pages

{

    public partial class DescriptionPage : Page

    {

        public DescriptionPage()

        {

            InitializeComponent();

        }

 

        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) {

            e.CanExecute = (description.Text.Length > 0); // 입력된 내용이 존재 하면 활성화

        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) {

            SummaryPage page = new SummaryPage(); // 아직 만들지 않음

            page.Description = description.Text; // 이번에는 속성 사용해 상태 확인

            NavigationService.Navigate(page); // 이동

        }

        // 텍스트 파일에 저장된 설명을 읽어서 텍스트 박스에 출력

        private void open_Executed(object sender, ExecutedRoutedEventArgs e) {

            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog().GetValueOrDefault()) {

                using (StreamReader reader = new StreamReader(dialog.FileName)) {

                    description.Text = reader.ReadToEnd();

                }

            }

        }

        // 변경된 설명을 파일로 저장

        private void save_Executed(object sender, ExecutedRoutedEventArgs e) {

            SaveFileDialog dialog = new SaveFileDialog();

            if (dialog.ShowDialog().GetValueOrDefault()) {

                using (StreamWriter writer = new StreamWriter(dialog.FileName)) {

                    writer.Write(description.Text);

                }

            }

        }

    }

} 

 

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;

using Contoso.Data; //

 

namespace PatientReferrals.Pages

{

    /// <summary>

    /// Interaction logic for DetailsPage.xaml

    /// </summary>

    public partial class DetailsPage : Page

    {

        public DetailsPage()

        {

            InitializeComponent();

        }

 

        private void patientSearch_Click(object sender, RoutedEventArgs e)

        {

            List<Patient> patientList = new List<Patient>(Patient.Patients);

 

            string searchText = patientName.Text;

            List<Patient> matches = patientList.FindAll(

                p => p.FirstName.Contains(searchText) || p.LastName.Contains(searchText));

 

            patientResults.ItemsSource = matches;

        }

 

        private void specialistSearch_Click(object sender, RoutedEventArgs e)

        {

            List<Specialist> specialistList =

                            new List<Specialist>(Specialist.Specialists);

 

            string searchText = specialistName.Text;

            List<Specialist> matches = specialistList.FindAll(

                s => s.Name.Contains(searchText));

 

            specialistResults.ItemsSource = matches;

        }

 

        // 해당 컨트롤에 대해서 활성화 여부 결정´

        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)

        {

            e.CanExecute =

                (patientResults.SelectedIndex >= 0 && specialistResults.SelectedIndex >= 0);

        }

        // 활성화된 컨트롤을 클릭 하였을때 실행되는 코드

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            // 다음 페이지로 값을 넘기지 않으려면 상태값 보관             
            Application
.Current.Properties["PATIENT"] = patientResults.SelectedValue;

            Application.Current.Properties["SPECIALIST"] = specialistResults.SelectedValue;

            // 다음 페이지로 이용

            NavigationService.Navigate(

                new Uri("Pages\\DescriptionPage.xaml", UriKind.Relative));

        }

    }

} 

 

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;

using Contoso.Data;

 

namespace PatientReferrals.Pages

{

    /// <summary>

    /// Interaction logic for SummaryPage.xaml

    /// </summary>

    public partial class SummaryPage : Page

    {

        public SummaryPage()

        {

            InitializeComponent();

        }

 

        private void Page_Loaded(object sender, RoutedEventArgs e)

        {

            // Populate the form with data.

            patientName.DataContext = Application.Current.Properties["PATIENT"];

            specialistName.DataContext = Application.Current.Properties["SPECIALIST"];

            descripiton.DataContext = this.Description;

        }

 

        private void send_Click(object sender, RoutedEventArgs e)

        {

            // Alert the user that the process is complete.

            MessageBox.Show("Patient information sent.", Title,

                MessageBoxButton.OK, MessageBoxImage.Information);

 

            RedirectToStart();

        }

 

        private void cancel_Click(object sender, RoutedEventArgs e)

        {

            RedirectToStart();

        }

 

        void RedirectToStart()

        {

            // Go back to the start page.

            // ...TODO

            // 다시 메인

            NavigationService.Navigate(

                new Uri("Pages\\DetailsPage.xaml", UriKind.Relative));

        }

 

        public string Description { get; set; }

    }

} 


반응형
posted by Magic_kit
2010. 5. 21. 01:29 .Net Project/WPF
반응형
1. 화면 UI 구성

<Page x:Class="WpfBrowserApplication.Page1"

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

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

      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

      mc:Ignorable="d"

      d:DesignHeight="300" d:DesignWidth="300"

      Title="Page1">

    <StackPanel>

        <Button x:Name="btnOK" Content="클릭하시오..." />

    </StackPanel>

</Page> 


2. F7 통한 코드 작성

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 WpfBrowserApplication

{

    /// <summary>

    /// Interaction logic for Page1.xaml

    /// </summary>

    public partial class Page1 : Page

    {

        public Page1()

        {

            InitializeComponent();

 

            btnOK.Click += new RoutedEventHandler(btnOK_Click);

        }

 

        void btnOK_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show(DateTime.Now.ToString());

        }

    }

} 


3. 결과 화면
 




반응형
posted by Magic_kit
2010. 5. 21. 01:22 .Net Project/WPF
반응형
1. 화면 UI 디자인

<Window x:Class="WpfHelloWorld.MainWindow"

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

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

        Title="MainWindow" Height="350" Width="525">

    <Grid>

        <Grid.RowDefinitions>

            <RowDefinition Height="30"></RowDefinition>

            <RowDefinition Height="*"></RowDefinition>

            <RowDefinition Height="30"></RowDefinition>

        </Grid.RowDefinitions>

        <TextBox Name="txtMessage" Grid.Row="0" Margin="5, 5, 5, 5" />

        <Button Name="btnOK" Content="" Grid.Row="2" />

    </Grid>

</Window> 


2. 디자인 모드에서 F7 코드 비하인드 페이지에서 다음과 같이 이벤트를 추가하여 준다

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 WpfHelloWorld

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

 

            btnOK.Click += new RoutedEventHandler(btnOK_Click);

        }

 

        void btnOK_Click(object sender, RoutedEventArgs e)

        {

            MessageBox.Show(txtMessage.Text);

        }

    }

} 


3. 결과 화면 입니다...



 





MessageBox.Show ("텍스트박스내용")
을 다음과 같이 출력해주고 있습니다..
반응형
posted by Magic_kit
2010. 5. 21. 01:14 .Net Project/WPF
반응형
파일 - > NEW - > 새로운 프로젝트

WPF 응용 프로그램 추가

위의 내용 같이 추가 새로운 응용 프로그램 WPF Application 추가하여 사용하도록 한다.

처음 생성시 솔루션 탐색기 (Ctrl + Alt + L) 화면 입니다.

반응형
posted by Magic_kit