Hour 5 Using Basic Controls
컨트롤은 사용자와의 특정한 상호 동작을 제공하는 사용자 인터페이스 컴포넌트 이다
WPF 컨트롤들은 외관은 변경할 수 있지만 컨트롤의 동작은 기본적으로 변경할 수 없다
-
TextBlock
<TextBlock FontSize="14" TextWrapping="Wrap"> <Bold><Italic>Instructions</Italic></Bold> <LineBreak /> select a <Underline>font</Underline> to view from the list <Italic>below</Italic> <Span FontSize="10">you can change the text by typing in the region at the bottom</Span> </TextBlock> |
<Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock Text="First Name:" /> <TextBox x:Name="firstname" Grid.Column="1" />
<TextBlock Grid.Row="1" Text="Last Name:" /> <TextBox x:Name="lastname" Grid.Row="1" Grid.Column="1" />
<TextBlock Grid.Row="2" Text="Sex:" /> <TextBox x:Name="sex" Grid.Row="2" Grid.Column="1" />
<TextBlock Grid.Row="3" Text="Additional Notes:" /> <TextBox x:Name="additionalNotes" Grid.Row="3" Grid.Column="1" MinLines="5" /> |
<TextBox x:Name="additionalNotes" Grid.Row="3" Grid.Column="1" MinLines="5" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap"/> |
AcceptsReturn="True" -> 여러 줄의 텍스트를 편집 할 수 있다
AcceptsTab="True" -> 탭 기능을 쓸 수 있다
-
Label
<Grid> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions>
<Label Target="{Binding ElementName=firstName}" > <Border BorderBrush="Blue" BorderThickness="2 0" CornerRadius="3" Padding="2"> <AccessText>_First Name</AccessText> </Border> </Label> <TextBox x:Name="firstName" Grid.Column="1" />
<Label Grid.Row="1" Content="_Last Name: " Target="{Binding ElementName=lastName}" /> <TextBox x:Name="lastName" Grid.Row="1" Grid.Column="1" />
<Label Grid.Row="2" Content="Se_x" Target="{Binding ElementName=sex}" /> <TextBox x:Name="sex" Grid.Row="2" Grid.Column="1" />
<Label Grid.Row="3" Content="Additional _Notes:" Target="{Binding ElementName=additionalNotes}" />
<TextBox x:Name="additionalNotes" Grid.Row="3" Grid.Column="1" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap" VerticalAlignment="Stretch" SpellCheck.IsEnabled="True" ToolTip="type additional notes here" /> </Grid> |
-
Button
버튼은 사용자가 클릭할 수 있는 컨트롤이다
<Grid> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="auto" /> <RowDefinition Height="*" /> <RowDefinition Height="auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Label Target="{Binding ElementName=firstName}" Content="_First Name:" /> <TextBox x:Name="firstName" Grid.Column="1" />
<Label Grid.Row="1" Content="_Last Name:" Target="{Binding ElementName=lastName}" /> <TextBox x:Name="lastName" Grid.Row="1" Grid.Column="1" />
<Label Grid.Row="2" Content="Se_x:" Target="{Binding ElementName=male}" /> <WrapPanel Grid.Row="2" Grid.Column="1" VerticalAlignment="Center"> <RadioButton x:Name="male" GroupName="sex" Content="Male" Margin="3" /> <RadioButton GroupName="sex" Content="Female" Margin="3" /> </WrapPanel> <Label Grid.Row="3" Content="_Education:" Target="{Binding ElementName=highSchool}" /> <WrapPanel Grid.Row="3" Grid.Column="1"> <CheckBox x:Name="highSchool" Content="High School" Margin="2" /> <CheckBox Content="Bachelor's" Margin="2" /> <CheckBox Content="Master's" Margin="2" /> <CheckBox Content="Doctorate" Margin="2" /> </WrapPanel>
<Label Grid.Row="4" Content="Additional _Notes:" Target="{Binding ElementName=additionalNotes}" /> <TextBox x:Name="additionalNotes" Grid.Row="4" Grid.Column="1" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap" VerticalAlignment="Stretch" SpellCheck.IsEnabled="True" /> <Button Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" Click="Button_Click"> <AccessText>_Save</AccessText> </Button> </Grid>
private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show("contact saved", "save"); } |
-
ListBox
<Grid> <ListBox Background="AliceBlue"> <ListBoxItem>apple</ListBoxItem> <ListBoxItem>banana</ListBoxItem> <ListBoxItem>grape</ListBoxItem> </ListBox> </Grid> |
출처: programming wpf 사용자 경험을 바꾸는 기술