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["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; } } } |
'.Net Project > WPF' 카테고리의 다른 글
06. WPF AddressBook 주소록 간단 출력 응용 프로그램 작성 (0) | 2010.05.21 |
---|---|
05. WPF Windows 바탕화면 변경하기 (0) | 2010.05.21 |
03. WPF 웹 브라우저 실행하여 날짜값 출력 (0) | 2010.05.21 |
02. WPF HelloWorld 텍스트 박스 내용 메시지 박스에 출력 (0) | 2010.05.21 |
01. WPF 시작하기 (0) | 2010.05.21 |