UWP入门(八)--几个简单的控件
每天看几个,要不聊几天我就可以看完啦,加油!
看效果
1. CheckBox
      <TextBlock Grid.Row="0" Text="CheckBox" VerticalAlignment="Center" />
        <StackPanel Grid.Column="1"
                    Margin="20,10,0,10"
                    Orientation="Horizontal">
            <CheckBox Name="MyCheckBox"
                      Content="Agree?"
                      Tapped="MyCheckBox_Tapped" />
            <TextBlock Name="CheckBoxResultTextBlock" />
        </StackPanel>  private void MyCheckBox_Tapped(object sender, TappedRoutedEventArgs e)
        {
            CheckBoxResultTextBlock.Text = MyCheckBox.IsChecked.ToString();
        }2. RadioButton
 <TextBlock Grid.Row="2"
                   Text="RadioButton"
                   VerticalAlignment="Center" />
        <StackPanel Grid.Row="2"
                    Grid.Column="1"
                    Orientation="Horizontal"
                    Margin="20,10,0,10">
            <RadioButton Name="YesRadioButton"
                         Content="Yes"
                         GroupName="MyGroup"
                         Checked="RadioButton_Checked" />
            <RadioButton Name="NoRadioButton"
                         Content="No"
                         GroupName="MyGroup"
                         Checked="RadioButton_Checked" />
            <TextBlock Name="RadioButtonTextBlock" />
        </StackPanel> private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButtonTextBlock.Text = (bool)YesRadioButton.IsChecked ? "Yes" : "No";
        }3. CombomBox
 <TextBlock Grid.Row="3"
                   Text="ComboBox"
                   Name="MyComboBox"
                   VerticalAlignment="Center" />
        <StackPanel Orientation="Horizontal"
                    Grid.Row="3"
                    Grid.Column="1"
                    Margin="20,10,0,10">
            <ComboBox SelectionChanged="ComboBox_SelectionChanged" >
                <ComboBoxItem Content="Fourth" />
                <ComboBoxItem Content="Fifth" />
                <ComboBoxItem Content="Sixth" IsSelected="True" />
            </ComboBox>
            <TextBlock Name="ComboBoxResultTextBlock" />
        </StackPanel>private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxResultTextBlock == null) return;
            var combo = (ComboBox)sender;
            var item = (ComboBoxItem)combo.SelectedItem;
            ComboBoxResultTextBlock.Text = item.Content.ToString();
        }4. ListBox
  <TextBlock Grid.Row="4" Text="ListBox" VerticalAlignment="Center" />
        <StackPanel Grid.Row="4" Grid.Column="1"  Margin="20,10,0,10">
            <ListBox Name="MyListBox"
                     SelectionMode="Multiple"
                     SelectionChanged="ListBox_SelectionChanged">
                <ListBoxItem Content="First" />
                <ListBoxItem Content="Second" />
                <ListBoxItem Content="Third" />
            </ListBox>
            <TextBlock Name="ListBoxResultTextBlock" />
        </StackPanel>       private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedItems = MyListBox.Items.Cast<ListBoxItem>()
                                  .Where(p => p.IsSelected)
                                    .Select(t => t.Content.ToString())
                                      .ToArray();
            ListBoxResultTextBlock.Text = string.Join(", ", selectedItems);
        }5. image
 <TextBlock Grid.Row="5" Text="Image" VerticalAlignment="Center" />
        <Image Source="Assets/StoreLogo.png"
               HorizontalAlignment="Left"
               Width="250"
               Height="50"
               Grid.Row="5"
               Grid.Column="1"
               Stretch="Uniform"
               Margin="20,10,0,10" />image 的四种拉伸方法
- None
- 不做任何处理,一般比较大
 
- Fill  
 - 占据所给的最大空间,比例会失调
 
- Uniform  
 - 按比例伸缩,占据所给的最大空间
 
- UniformFill  
 - 按比例伸缩,占据大小
 
6. 漂亮的 ToggleSwitch
<TextBlock Grid.Row="8"
                   Text="ToggleSwitch"
                   VerticalAlignment="Center" />
        <StackPanel Grid.Row="8"
                      Grid.Column="1"
                      Margin="20,10,0,10" >
            <ToggleSwitch>
                <ToggleSwitch.OffContent>
                    <TextBlock Text="I'm off right now." />
                </ToggleSwitch.OffContent>
                <ToggleSwitch.OnContent>
                    <TextBlock Text="I'm on!" />
                </ToggleSwitch.OnContent>
            </ToggleSwitch>
        </StackPanel>不需要代码
7. ToggleButton
<TextBlock Grid.Row="7" Text="ToggleButton" VerticalAlignment="Center"  />
        <StackPanel Orientation="Horizontal"
                    Grid.Row="7"
                    Grid.Column="1"
                    Margin="20,10,0,10" >
            <ToggleButton Name="MyToggleButton"
                          Content="Premium Option"
                          IsThreeState="True"
                          Click="MyToggleButton_Click" />
            <TextBlock Name="ToggleButtonResultTextBlock" />
        </StackPanel> private void MyToggleButton_Click(object sender, RoutedEventArgs e)
        {
            ToggleButtonResultTextBlock.Text = MyToggleButton.IsChecked.ToString();
        }代码
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,10,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Text="CheckBox" VerticalAlignment="Center" />
        <StackPanel Grid.Column="1"
                    Margin="20,10,0,10"
                    Orientation="Horizontal">
            <CheckBox Name="MyCheckBox"
                      Content="Agree?"
                      Tapped="MyCheckBox_Tapped" />
            <TextBlock Name="CheckBoxResultTextBlock" />
        </StackPanel>
        <TextBlock Grid.Row="2"
                   Text="RadioButton"
                   VerticalAlignment="Center" />
        <StackPanel Grid.Row="2"
                    Grid.Column="1"
                    Orientation="Horizontal"
                    Margin="20,10,0,10">
            <RadioButton Name="YesRadioButton"
                         Content="Yes"
                         GroupName="MyGroup"
                         Checked="RadioButton_Checked" />
            <RadioButton Name="NoRadioButton"
                         Content="No"
                         GroupName="MyGroup"
                         Checked="RadioButton_Checked" />
            <TextBlock Name="RadioButtonTextBlock" />
        </StackPanel>
        <TextBlock Grid.Row="3"
                   Text="ComboBox"
                   Name="MyComboBox"
                   VerticalAlignment="Center" />
        <StackPanel Orientation="Horizontal"
                    Grid.Row="3"
                    Grid.Column="1"
                    Margin="20,10,0,10">
            <ComboBox SelectionChanged="ComboBox_SelectionChanged" >
                <ComboBoxItem Content="Fourth" />
                <ComboBoxItem Content="Fifth" />
                <ComboBoxItem Content="Sixth" IsSelected="True" />
            </ComboBox>
            <TextBlock Name="ComboBoxResultTextBlock" />
        </StackPanel>
        <TextBlock Grid.Row="4" Text="ListBox" VerticalAlignment="Center" />
        <StackPanel Grid.Row="4" Grid.Column="1"  Margin="20,10,0,10">
            <ListBox Name="MyListBox"
                     SelectionMode="Multiple"
                     SelectionChanged="ListBox_SelectionChanged">
                <ListBoxItem Content="First" />
                <ListBoxItem Content="Second" />
                <ListBoxItem Content="Third" />
            </ListBox>
            <TextBlock Name="ListBoxResultTextBlock" />
        </StackPanel>
        <TextBlock Grid.Row="5" Text="Image" VerticalAlignment="Center" />
        <Image Source="Assets/StoreLogo.png"
               HorizontalAlignment="Left"
               Width="250"
               Height="50"
               Grid.Row="5"
               Grid.Column="1"
               Stretch="Uniform"
               Margin="20,10,0,10" />
        <TextBlock Grid.Row="7" Text="ToggleButton" VerticalAlignment="Center"  />
        <StackPanel Orientation="Horizontal"
                    Grid.Row="7"
                    Grid.Column="1"
                    Margin="20,10,0,10" >
            <ToggleButton Name="MyToggleButton"
                          Content="Premium Option"
                          IsThreeState="True"
                          Click="MyToggleButton_Click" />
            <TextBlock Name="ToggleButtonResultTextBlock" />
        </StackPanel>
        <TextBlock Grid.Row="8"
                   Text="ToggleSwitch"
                   VerticalAlignment="Center" />
        <StackPanel Grid.Row="8"
                      Grid.Column="1"
                      Margin="20,10,0,10" >
            <ToggleSwitch>
                <ToggleSwitch.OffContent>
                    <TextBlock Text="I'm off right now." />
                </ToggleSwitch.OffContent>
                <ToggleSwitch.OnContent>
                    <TextBlock Text="I'm on!" />
                </ToggleSwitch.OnContent>
            </ToggleSwitch>
        </StackPanel>
    </Grid>cs 代码
public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
        private void MyCheckBox_Tapped(object sender, TappedRoutedEventArgs e)
        {
            CheckBoxResultTextBlock.Text = MyCheckBox.IsChecked.ToString();
        }
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButtonTextBlock.Text = (bool)YesRadioButton.IsChecked ? "Yes" : "No";
        }
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxResultTextBlock == null) return;
            var combo = (ComboBox)sender;
            var item = (ComboBoxItem)combo.SelectedItem;
            ComboBoxResultTextBlock.Text = item.Content.ToString();
        }
        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedItems = MyListBox.Items.Cast<ListBoxItem>()
                                  .Where(p => p.IsSelected)
                                    .Select(t => t.Content.ToString())
                                      .ToArray();
            ListBoxResultTextBlock.Text = string.Join(", ", selectedItems);
        }
        private void MyToggleButton_Click(object sender, RoutedEventArgs e)
        {
            ToggleButtonResultTextBlock.Text = MyToggleButton.IsChecked.ToString();
        }
    }UWP入门(八)--几个简单的控件的更多相关文章
- (八)ASP.NET自定义用户控件(1)
		http://blog.csdn.net/laodao1/article/details/5897366 ASP.NET自定义控件组件开发 第一章:从一个简单的控件谈起 起始开发ASP.NET自定义控 ... 
- ASP.NET自定义控件组件开发 第一章    第一章:从一个简单的控件谈起
		第一章:从一个简单的控件谈起 系列文章链接: ASP.NET自定义控件组件开发 第一章 待续 ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 ASP.NET自定义控件组件开发 第一章 第三 ... 
- [译]Kinect for Windows SDK开发入门(十八):Kinect Interaction交互控件
		本文译自 http://dotneteers.net/blogs/vbandi/archive/2013/03/25/kinect-interactions-with-wpf-part-i-getti ... 
- UWP &WP8.1 依赖属性和用户控件 依赖属性简单使用 uwp添加UserControl
		上面说 附加属性.这章节说依赖属性. 所谓依赖属性.白话讲就是添加一个公开的属性. 同样,依赖属性的用法和附加属性的用法差不多. 依赖属性是具有一个get,set的属性,以及反调函数. 首先是声明依赖 ... 
- VS2010/MFC编程入门之二十三(常用控件:按钮控件的编程实例)
		上一节VS2010/MFC编程入门教程中鸡啄米讲了按钮控件Button.Radio Button和Check Box的基本用法,本节就继续讲按钮控件的内容,通过一个实例让大家更清楚按钮控件在实际的软件 ... 
- duilib教程之duilib入门简明教程15.自绘控件
		在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如菜单控件 ... 
- UWP开发必备:常用数据列表控件汇总比较
		今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ... 
- Android入门(六):Android控件布局属性全解
		第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中 (Hrizontal表示水平)android:layout_centerVertical 垂 ... 
- MFC编程入门之二十七(常用控件:图片控件PictureControl)
		上一节讲的是滚动条控件,本节主要讲一种简单实用的控件,图片控件Picture Control.我们可以在界面某个位置放入图片控件,显示图片以美化界面. 图片控件简介 图片控件和前面讲到的静态文本框都是 ... 
随机推荐
- 检索08- SQL语句中的go与use用法
			GO 1. 作用:向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号.2. 语法:一批 Transact-SQL 语句 GO 如 Select 1 Select 2 ... 
- 微信Android终端SDK新手使用指南
			1.申请你的AppID 请到 开发者应用登记页面 进行登记,登记并选择移动应用进行设置后,将获得AppID,可立即用于开发.但应用登记完成后还需要提交审核,只有审核通过的应用才能正式发布使用. 2.下 ... 
- C# keybd_event用法 模拟键盘输入
			最近有业务需求,需要模拟键盘输入,所以了解了一下C#中keybd_event函数的用法.该函数能够产生WM_KEYUP或WM_KEYDOWN消息,即可以触发键盘事件. 函数引用如下: [DllImpo ... 
- DDD的.NET开发框架
			基于DDD的.NET开发框架ABP实例,多租户 (Sass)应用程序,采用.NET MVC, Angularjs, EntityFramework-介绍 介绍 基于ABPZERO的多租户 (Sass) ... 
- jQuery插件实现的页面功能介绍引导页效果
			新产品上线或是改版升级,我们会在用户第一次使用产品时建立一个使用向导,引导用户如何使用产品,如使用演示的方式逐一介绍界面上的功能模块,从而提升了用户体验和产品的亲和力. Helloweba.com之前 ... 
- Android ActionBar相关
			1.Android 5.0 删除ActionBar下面的阴影 于Android 5.0假设你发现的ActionBar下面出现了阴影,例如,下面的设置,以消除阴影: getActionBar().set ... 
- 深度学习实践指南(六)—— ReLU(前向和后向过程)
			def relu_forward(x): out = x * (x > 0) # * 对于 np.ndarray 而言表示 handmard 积,x > 0 得到的 0和1 构成的矩阵 r ... 
- Android中使用JUnit测试
			package com.meritit.lottery.test; import java.util.List; import android.test.AndroidTestCase; import ... 
- WPF的逻辑树与视觉树(1)基本概念
			原文:WPF的逻辑树与视觉树(1)基本概念 一.摘要 逻辑树与视觉树属于WPF的基本概念,学过WPF或者Silverlight的朋友一定会对其有所耳闻,这篇文章将来探讨逻辑树与视觉树的特质以及 ... 
- 《用户体验要素》澄清了 UI 原型设计中看不见确感受得到的那一层
			<用户体验要素>澄清了看不见确感受得到的那一层 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&quo ... 
