背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
2021-05-12 22:26
标签:http ext extend multi type resource 数据 block mode [源码下载] 作者:webabcd 示例 Controls/SelectionControl/ListBoxDemo.xaml.cs Controls/SelectionControl/RadioButtonDemo.xaml.cs Controls/SelectionControl/CheckBoxDemo.xaml.cs Controls/SelectionControl/ToggleSwitchDemo.xaml.cs OK 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 标签:http ext extend multi type resource 数据 block mode 原文地址:http://www.cnblogs.com/lonelyxmas/p/7567313.html
介绍
背水一战 Windows 10 之 控件(选择类)
1、ListBox 的示例
Controls/SelectionControl/ListBoxDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.ListBoxDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:common="using:Windows10.Common">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10" Orientation="Horizontal">
ListBox x:Name="listBox1" Margin="5" Width="200" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top">
ListBox.Items>
ListBoxItem Content="ListBoxItem1" />
ListBoxItem Content="ListBoxItem2" />
ListBoxItem Content="ListBoxItem3" />
ListBoxItem Content="ListBoxItem4" />
ListBoxItem Content="ListBoxItem5" />
ListBox.Items>
ListBox>
ListBox x:Name="listBox2" Margin="5" ItemsSource="{x:Bind Employees}" Width="200" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top">
ListBox.ItemTemplate>
DataTemplate x:DataType="common:Employee">
StackPanel Orientation="Horizontal">
TextBlock Text="{x:Bind Name}" />
TextBlock Text="{x:Bind Age}" Margin="5 0 0 0" />
StackPanel>
DataTemplate>
ListBox.ItemTemplate>
ListBox>
TextBlock Name="lblMsg2" Margin="5" Width="300" TextWrapping="Wrap" />
StackPanel>
Grid>
Page>
/*
* ListBox - 列表框控件(继承自 Selector, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
* SelectionMode - 选择的模式
* Single - 单选(默认)
* Multiple - 仅通过鼠标多选
* Extended - 通过鼠标和辅助键(ctrl, shift)多选
* ScrollIntoView(object item) - 滚动到指定数据对象
* SelectAll() - 选中所有项
* SelectedItems - 获取当前选中的数据对象集合
*
*
* ListBoxItem - 列表框控件的 item(继承自 SelectorItem, 请参见 /Controls/SelectionControl/SelectorDemo.xaml)
*/
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
using Windows10.Common;
using System.Linq;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class ListBoxDemo : Page
{
public ObservableCollection
2、RadioButton 的示例
Controls/SelectionControl/RadioButtonDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.RadioButtonDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
RadioButton Name="rad1" GroupName="groupName1" Margin="5" IsChecked="True" Content="groupName1 - RadioButton1" />
RadioButton Name="rad2" GroupName="groupName1" Margin="5" Content="groupName1 - RadioButton2" />
RadioButton Name="rad3" GroupName="groupName2" Margin="5" IsChecked="True" Content="groupName2 - RadioButton1" />
RadioButton Name="rad4" GroupName="groupName2" Margin="5" Content="groupName2 - RadioButton2" />
StackPanel>
Grid>
Page>
/*
* RadioButton - 单选框控件(继承自 ToggleButton, 请参见 /Controls/ButtonControl/ToggleButtonDemo.xaml)
*/
using Windows.UI.Xaml.Controls;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class RadioButtonDemo : Page
{
public RadioButtonDemo()
{
this.InitializeComponent();
}
}
}
3、CheckBox 的示例
Controls/SelectionControl/CheckBoxDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.CheckBoxDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
CheckBox Name="chk1" Margin="5" IsChecked="True" Content="CheckBox1" />
CheckBox Name="chk2" Margin="5" IsChecked="False" Content="CheckBox2" />
StackPanel>
Grid>
Page>
/*
* CheckBox - 复选框控件(继承自 ToggleButton, 请参见 /Controls/ButtonControl/ToggleButtonDemo.xaml)
*/
using Windows.UI.Xaml.Controls;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class CheckBoxDemo : Page
{
public CheckBoxDemo()
{
this.InitializeComponent();
}
}
}
4、ToggleSwitch 的示例
Controls/SelectionControl/ToggleSwitchDemo.xamlPage
x:Class="Windows10.Controls.SelectionControl.ToggleSwitchDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.SelectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
TextBlock Name="lblMsg" Margin="5" />
ToggleSwitch Name="toggleSwitch1" Margin="5" Header="wifi1" OnContent="OnContent" OffContent="OffContent" IsOn="True"
Toggled="toggleSwitch1_Toggled"
Style="{StaticResource MyToggleSwitchStyle}" />
ToggleSwitch Name="toggleSwitch2" Margin="5" IsOn="True" Style="{StaticResource MyToggleSwitchStyle}">
ToggleSwitch.HeaderTemplate>
DataTemplate>
TextBlock Text="wifi2" Foreground="Yellow" />
DataTemplate>
ToggleSwitch.HeaderTemplate>
ToggleSwitch.OnContentTemplate>
DataTemplate>
TextBlock Text="OnContent" Foreground="Orange" />
DataTemplate>
ToggleSwitch.OnContentTemplate>
ToggleSwitch.OffContentTemplate>
DataTemplate>
TextBlock Text="OffContent" Foreground="Blue" />
DataTemplate>
ToggleSwitch.OffContentTemplate>
ToggleSwitch>
StackPanel>
Grid>
Page>
/*
* ToggleSwitch - 状态切换控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
*/
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Windows10.Controls.SelectionControl
{
public sealed partial class ToggleSwitchDemo : Page
{
public ToggleSwitchDemo()
{
this.InitializeComponent();
}
private void toggleSwitch1_Toggled(object sender, RoutedEventArgs e)
{
lblMsg.Text = $"toggleSwitch1_Toggled, IsOn:{toggleSwitch1.IsOn}";
}
}
}
[源码下载]
文章标题:背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
文章链接:http://soscw.com/index.php/essay/84871.html