怎么做影视类网站,域名一级和二级的区别,西安模板网站建设,网站开发公司 上【 声明#xff1a;版权所有#xff0c;欢迎转载#xff0c;请勿用于商业用途。 联系信箱#xff1a;feixiaoxing 163.com】 在软件开发中#xff0c;属性或者参数设置是很重要的一个部分。这个时候如果不想通过动态添加控件的方法来处理的话#xff0c;那么可以通过tab控…【 声明版权所有欢迎转载请勿用于商业用途。 联系信箱feixiaoxing 163.com】 在软件开发中属性或者参数设置是很重要的一个部分。这个时候如果不想通过动态添加控件的方法来处理的话那么可以通过tab控件来解决。tab控件的好处很多最大的优点就是可以实现单个page上面放置尽可能多的属性设置。 以某汽车设备来说如果是单页面那么只能放置一些常用的内容。但是如果是tab页面可以添加多个tab比如大灯、空调、动力、安全、音乐、座椅等等基本上你想放多少个tab就可以放多少tab。每一个tab下面都是独立的页面里面也可以放很多的子控件。以音乐为例可以调节音量大小、播放方式、歌曲类型、歌手类型、专辑类型等等这些都是可以灵活设置的。 用c# wpf开发tab也是很方便的。主要的操作都是在xaml文件配置完成的并不需要添加太多的代码内容。 1、xaml设计
Window x:ClassWpfApp.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfAppmc:IgnorabledTitleMainWindow Height450 Width600Grid TabControlTabItem HeaderTab 1StackPanelTextBlock TextThis is Tab 1 /Button ContentClick me Height40 Width60 ClickButton_Click //StackPanel/TabItemTabItem HeaderTab 2TextBlock TextThis is Tab 2 //TabItem/TabControl/Grid
/Window为了说明tab如果使用这里添加了一个tab control、两个tab item。tab control相当于tab的总入口在tab里面有两个tab子页面也就是tab item的部分。第一个tab item的名字叫tab 1子页面里面又添加了一个text block和一个button。第二个tab item里面就比较简单这里只是添加了一个text block。设计完成之后显示出来的效果就是这样的 整个xaml是所见即所得的xaml修改好之后马上就可以看到对应的效果。tab control和tab item控件也是一样。 2、代码部分 和xaml相比较代码部分就比较少这里主要就是一个按钮的回调函数Button_Click实现的内容也就是弹出一个消息对话框而已。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Threading;namespace WpfApp
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){MessageBox.Show(Button in Tab 1 clicked!);}}}编译运行后效果就是这样的 3、后续建议 从实用的角度来说tab非常非常地方便特别是如果关联的对象参数比较多那么完全可以用tab来实现对应地功能很好用。记得以前用mfc编写界面的时候非常麻烦需要这里添加代码、那里添加代码xaml文件没有这个烦恼所见即所得修改之后马上就可以看到效果。这是mfc之类的gui编辑软件没有办法比拟的。 4、其他 关于tab、grid、tree这一列的控件都可以看成是容器控件。如果说另外一种用的比较多的控件可能groupbox也算一类吧大家平时开发的时候可以多多尝试多多练习。
Window x:ClassWpfApp.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfAppmc:IgnorabledTitleMainWindow Height450 Width600GridGrid.ColumnDefinitionsColumnDefinition Width160/ColumnDefinition Width*//Grid.ColumnDefinitions!-- 主容器 --GroupBox Grid.Column0 HeaderGender Margin10,10,10,10StackPanel!-- RadioButton 分组1 --RadioButton ContentMale GroupNameGenderGroup Margin5/RadioButton ContentFemale GroupNameGenderGroup Margin5//StackPanel/GroupBox/Grid
/Window 对应的效果是这样的