TabControl
1. ItemsSource="{Binding GroupList}" SelectedItem="{Binding SelectedGroupItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemsSource:绑定的数据列表
SelectedItem:当前选中项
2.<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock></TextBlock>
<TextBlock Text="{Binding GroupName}" Tag="{Binding GroupName}" MaxWidth="80" TextTrimming="WordEllipsis"></TextBlock>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
这里的意思是在TabControl的标签上,做了一个TextBlock,数据绑定的是GroupName,班级名,级“一班”,“二班”,“三班”

3.TabControl中使用了ListBox,注意事项


using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Net;
using System.IO;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Runtime.InteropServices;
using System.Xml;
using MVVM.Model;
using System.Xml.Linq;
using System.Windows;
using MVVM.communication;
using System.Threading;
using Microsoft.Win32;
using MVVM.Service;
using MVVM.ftp;
using System.Linq;
using System.Collections.ObjectModel; namespace MVVM.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
/// <summary>
/// TabControl 绑定的数据列表
/// </summary>
public ObservableCollection<StudentGroup> GroupList//ObservableCollection
{
get { return _groupList; }
set { Set(() => GroupList, ref _groupList, value); }
}
private ObservableCollection<StudentGroup> _groupList = new ObservableCollection<StudentGroup>(); /// <summary>
/// 当前选中的TabControl
/// </summary>
public StudentGroup SelectedGroupItem
{
get { return _selectedGroupItem; }
set { Set(() => SelectedGroupItem, ref _selectedGroupItem, value); }
}
private StudentGroup _selectedGroupItem; public MainViewModel()
{
//TabControl 绑定的数据列表 初始化
ObservableCollection<Student> g1StuList = new ObservableCollection<Student>();
Student s1 = new Student(,"zhangsan","","bj");
g1StuList.Add(s1);
StudentGroup g1 = new StudentGroup(,"一班","学习好",g1StuList); ObservableCollection<Student> g2StuList = new ObservableCollection<Student>();
Student s2 = new Student(, "lisi", "", "bj");
Student s3 = new Student(, "wanger", "", "bj");
Student s4 = new Student(, "maqi", "", "bj");
Student s5 = new Student(, "gouba", "", "bj");
g2StuList.Add(s2);
g2StuList.Add(s3);
g2StuList.Add(s4);
g2StuList.Add(s5);
StudentGroup g2 = new StudentGroup(, "二班", "爱玩", g2StuList); ObservableCollection<Student> g3StuList = new ObservableCollection<Student>();
Student s6 = new Student(, "zhangsan", "", "shanghai");
Student s7 = new Student(, "zhangsan", "", "nanjing");
g3StuList.Add(s6);
g3StuList.Add(s7);
StudentGroup g3 = new StudentGroup(, "三班", "体育好", g3StuList); GroupList.Add(g1);
GroupList.Add(g2);
GroupList.Add(g3); //当前选中的TabControl 赋初值
SelectedGroupItem = GroupList[]; } }
}
<Window x:Class="MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
Title="MainWindow" Height="600" Width="700">
<Window.DataContext>
<Binding Path="Main" Source="{StaticResource Locator}"></Binding>
</Window.DataContext>
<Grid>
<Grid.Resources>
<Style x:Key="BackColor" TargetType="Rectangle">
<Setter Property="Fill" Value="Black"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="*"/> </Grid.RowDefinitions> <TabControl ItemsSource="{Binding GroupList}" SelectedItem="{Binding SelectedGroupItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="0,10,0,54" Grid.RowSpan="4">
<!--<TabControl.Resources>
<Style></Style>
</TabControl.Resources>-->
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock></TextBlock>
<TextBlock Text="{Binding GroupName}" Tag="{Binding GroupName}" MaxWidth="80" TextTrimming="WordEllipsis"></TextBlock>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<!--<DataTemplate.Resources>
<Style></Style>
</DataTemplate.Resources>-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<StackPanel>
<StackPanel>
<TextBlock Text="班级ID" Grid.Column="0" Grid.Row="0"></TextBlock>
<TextBlock Text="{Binding GroupID}" Grid.Column="1" Grid.Row="0"></TextBlock>
</StackPanel>
<StackPanel>
<TextBlock Text="班级名称" Grid.Column="0" Grid.Row="1"></TextBlock>
<TextBlock Text="{Binding GroupName}" Grid.Column="1" Grid.Row="1"></TextBlock>
</StackPanel>
<StackPanel>
<TextBlock Text="班级描述" Grid.Column="0" Grid.Row="2"></TextBlock>
<TextBlock Text="{Binding GroupDesc}" Grid.Column="1" Grid.Row="2"></TextBlock>
</StackPanel>
</StackPanel>
<!-- 横线-->
<Rectangle Grid.Row="1" Margin="5,0,30,5" Height="2" VerticalAlignment="Center" HorizontalAlignment="Stretch"></Rectangle>
<ScrollViewer Grid.Row="2" CanContentScroll="False" Focusable="False" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding StuList}">
<!--<ListBox.Resources>
<Style></Style>
</ListBox.Resources>--> <ListBox.ItemTemplate>
<DataTemplate>
<Expander IsExpanded="True">
<Expander.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</Expander.HeaderTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Text="ID:"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock Text="{Binding ID}"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Text="电话:"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1">
<TextBlock Text="{Binding Telephone}"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0">
<TextBlock Text="地址:"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1">
<TextBlock Text="{Binding Address}"></TextBlock>
</StackPanel>
</Grid>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> </ScrollViewer>
</Grid> </DataTemplate>
</TabControl.ContentTemplate> </TabControl> <StackPanel Grid.Row="1"> <!--<Button Content="点击我" Command="{Binding ClickCommand}"></Button>-->
</StackPanel>
</Grid>
</Window>
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace MVVM.Model
{
public class StudentGroup : ObservableObject
{
public int GroupID
{
get { return _groupID; }
set { Set(() => GroupID, ref _groupID, value); }
}
private int _groupID;
public String GroupName
{
get { return _groupName; }
set { Set(() => GroupName, ref _groupName, value); }
}
private String _groupName; public String GroupDesc
{
get { return _groupDesc; }
set { Set(() => GroupDesc, ref _groupDesc, value); }
}
private String _groupDesc; public ObservableCollection<Student> StuList
{
get { return _stuList; }
set { Set(() => StuList, ref _stuList, value); }
}
private ObservableCollection<Student> _stuList = new ObservableCollection<Student>(); public StudentGroup(int id, String groupName, String groupDesc, ObservableCollection<Student> stuList)
{
this.GroupID = id;
this.GroupName = groupName;
this.GroupDesc = groupDesc;
this.StuList = stuList;
} public StudentGroup ()
{ }
}
}
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace MVVM.Model
{
public class Student : ObservableObject
{
public int ID
{
get { return _id; }
set { Set(() => ID, ref _id, value); }
}
private int _id;
public String Name
{
get { return _name; }
set { Set(() => Name, ref _name, value); }
}
private String _name;
public String Telephone
{
get { return _telephone; }
set { Set(() => Telephone, ref _telephone, value); }
}
private String _telephone;
public String Address
{
get { return _address; }
set { Set(() => Address, ref _address, value); }
}
private String _address; public Student(int id, String name, String tele, String address)
{
this.ID = id;
this.Name = name;
this.Telephone = tele;
this.Address = address;
}
}
}

TabControl的更多相关文章
- TabControl 伸缩式菜单 仿照 uwp SplitView
留下备用笔记 之前用的Frame+Page的切换content<类似于一个contentControl 干多个事情>,但是发现页面content内容控件多的时候,每一次切换都有点卡,点击了 ...
- WinForm中重绘TabControl选项卡标题
最近开发WinForm频繁使用了TabControl控件,这个控件的选项卡没有BackgroundImage这个属性,那么如何为其各个选项卡添加背景图片呢?(这里说的是每个TabPage的头部,也就是 ...
- [WPF系列]-基础系列 TabControl应用
引言 Tabcontrol控件也是我们在项目中经常用到的一个控件,用它将相关的信息组织在一起分类显示. 简介 ========================================= ...
- WPF自适应可关闭的TabControl 类似浏览器的标签页
效果如图: 虽然说是自适应可关闭的TabControl,但TabControl并不需要改动,不如叫自适应可关闭的TabItem. 大体思路:建一个用户控件,继承自TabItem,里面放个按钮,点击的时 ...
- [C#开发小技巧]解决WinForm控件TabControl闪烁问题
在用C#开发WinForm程序时,常发现TabControl出现严重的闪烁问题,这主要是由于TabControl控件在实现时会绘制默认的窗口背景.其实以下一段简单的代码可以有效的缓解该问题的发生.这就 ...
- c# 如何隐藏TabControl控件的标签
http://www.cnblogs.com/chenleiustc/archive/2009/11/25/1527813.html 方法一:将标签缩小到机会看不到:设置页面的大小模式会自动适合(会尽 ...
- DotNetBar TabControl的使用
这个和系统的TabPage不同,一个TabPage分为了DevComponents.DotNetBar.TabItem,DevComponents.DotNetBar.TabControlPanel两 ...
- DataGridView in TabControl and CellValidating lead to problems
I created a little form with a TabControl on it and a combobox. On the first page i added a DataGri ...
- 对TabControl的简单优化
之前由于忙于赶项目进度而忽视了软件的用户体验,界面挺难看,有一天看见组长优化了某个窗体,让人感觉完全不一样,我也不甘示弱,要把我的程序做顺眼一点才行.我的程序是一个以TabControl为主要容器的窗 ...
- TabControl 显示彩色的图示 (XE6 Firemonkey)
提示:Delphi 10 Seattle 透过 TImageList 来指定图标,就能显示原来图标的颜色. 下列方法只适用于 XE6 XE6 Firemonkey 里的 TabControl 可以将切 ...
随机推荐
- do_exit——>exit_notify()【转】
转自:http://blog.csdn.net/sunnybeike/article/details/6907322 版权声明:本文为博主原创文章,未经博主允许不得转载. /* * Send sign ...
- hdu 3047(扩展并查集)
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- failed to push some refs to 'git@github.com:laniu/liuna.git'报错原因
出现错误的主要原因是github中的README.md文件不在本地代码目录中 可以通过如下命令进行代码合并[注:pull=fetch+merge] git pull --rebase origin m ...
- Python3在Windows安装配置及简单试用
1,安装配置 安装版本是Python3.5,我的安装路径是E:\ImProgram\Python35 添加环境变量,将上述路径加入到path中 这样cmd打开命令窗口,输入python就能看到调用成功 ...
- 腾讯微信支付,程序员是如何让jQuery代码付钱的
微信支付和支付宝支付已经是我们生活中不可确实的两个金融软件了,也是必备的,小编认为小钱用微信,大钱用支付宝. 下面这个图是我们生活中用腾讯微信支付平台的最后一个页面,大家想不想知道这个页面是如果做出来 ...
- POJ 2524 Ubiquitous Religions (并查集)
Description 当今世界有很多不同的宗教,很难通晓他们.你有兴趣找出在你的大学里有多少种不同的宗教信仰.你知道在你的大学里有n个学生(0 < n <= 50000).你无法询问每个 ...
- tyvj——P1002 谁拿了最多奖学金
P1002 谁拿了最多奖学金 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005复赛提高组第一题 描述 某校的惯例是在每学期的期末考试之后发 ...
- Jenkins部署+svn
Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. 确保java工作环境jdk.tom ...
- 八. 输入输出(IO)操作1.输入输出基本概念
输入输出(I/O)是指程序与外部设备或其他计算机进行交互的操作.几乎所有的程序都具有输入与输出操作,如从键盘上读取数据,从本地或网络上的文件读取数据或写入数据等.通过输入和输出操作可以从外界接收信息, ...
- Delphi CRC32Verify控件
unit CRC32Verify; interface uses Windows, Messages, SysUtils, Classes, Forms; CONST table: ARRA ...