日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UWP入门(八)--几个简单的控件

發布時間:2025/4/14 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UWP入门(八)--几个简单的控件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
UWP入門(八)--幾個簡單的控件 原文: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();}} posted on 2017-09-20 13:16 NET未來之路 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/lonelyxmas/p/7560937.html

總結

以上是生活随笔為你收集整理的UWP入门(八)--几个简单的控件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。