WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据
原文:WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据

功能阐述
就上面那图片
刚开始 考虑使用 RowHeaderTemplate 来实现 发现总绑定不上数据 上官网查了一下

不支持上下文绑定 fffffffffffff
只能考虑样式了 经验不足 经验不足~
直接上前后台源码了
XAML
-
<Window
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="WpfApplication31.MainWindow"
-
Title="MainWindow" Height="350" Width="525">
-
<Window.Resources>
-
-
<Style x:Key="DataGridRowHeaderStyle1" TargetType="{x:Type DataGridRowHeader}">
-
<Setter Property="Template">
-
<Setter.Value>
-
<ControlTemplate TargetType="{x:Type DataGridRowHeader}">
-
<Grid Height="59.834" Width="207.908">
-
<Grid.ColumnDefinitions>
-
<ColumnDefinition Width="20*"/>
-
<ColumnDefinition Width="21*"/>
-
<ColumnDefinition Width="77*"/>
-
</Grid.ColumnDefinitions>
-
<Grid Grid.Column="2" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch">
-
<Grid.RowDefinitions>
-
<RowDefinition/>
-
<RowDefinition/>
-
</Grid.RowDefinitions>
-
<Grid HorizontalAlignment="Stretch" Height="Auto" Margin="0" Grid.Row="1" VerticalAlignment="Stretch">
-
<Grid.ColumnDefinitions>
-
<ColumnDefinition/>
-
<ColumnDefinition/>
-
</Grid.ColumnDefinitions>
-
<Border BorderBrush="#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
-
<Label Content="リーダー" HorizontalAlignment="Center" Height="Auto" Background="White" VerticalAlignment="Center" Margin="0"/>
-
</Border>
-
<Border BorderBrush="#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
-
<Label Content="" HorizontalAlignment="Center" Height="Auto" Background="White" VerticalAlignment="Center" Margin="0"/>
-
</Border>
-
</Grid>
-
<Border BorderBrush="#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
-
<Label Content="{Binding Name}" HorizontalAlignment="Center" Height="Auto" Background="White" VerticalAlignment="Center" Margin="0"/>
-
</Border>
-
</Grid>
-
<Border BorderBrush="#FFBFBFBF" BorderThickness="1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch" Width="Auto" Background="White">
-
<Label Content="{Binding Num}" HorizontalAlignment="Center" Height="Auto" Background="White" VerticalAlignment="Center" Margin="0"/>
-
</Border>
-
<Border BorderBrush="#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
-
<Label Content="{Binding Class_}" HorizontalAlignment="Center" Height="Auto" Background="White" VerticalAlignment="Center" Margin="0"/>
-
</Border>
-
</Grid>
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style>
-
-
</Window.Resources>
-
<Grid>
-
<DataGrid x:Name="dataGrid" CanUserAddRows = "false" AutoGenerateColumns="False" Margin="10,10,0,0" RowHeaderStyle="{DynamicResource DataGridRowHeaderStyle1}" >
-
<DataGrid.Columns>
-
<DataGridTextColumn Header="姓名" Binding="{Binding Name}"/>
-
<DataGridTextColumn Header="年龄" Binding="{Binding Class_}"/>
-
</DataGrid.Columns>
-
-
</DataGrid>
-
-
</Grid>
-
</Window>
后台代码
-
using System;
-
using System.Collections.Generic;
-
using System.Collections.ObjectModel;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Linq;
-
using System.Text;
-
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;
-
-
namespace WpfApplication31
-
{
-
/// <summary>
-
/// MainWindow.xaml 的交互逻辑
-
/// </summary>
-
public partial class MainWindow : Window
-
{
-
public MainWindow()
-
{
-
InitializeComponent();
-
dataGrid.ItemsSource = GetNameData();
-
}
-
ObservableCollection<NameList> listName = new ObservableCollection<NameList>();
-
private ObservableCollection<NameList> GetNameData()
-
{
-
-
-
listName.Add(new NameList("市川 賞子", "リーダー", "B", 1));
-
listName.Add(new NameList("石田", "リーダー", "C", 2));
-
listName.Add(new NameList("安达 鮎美", "リーダー", "C", 3));
-
-
return listName;
-
-
}
-
-
}
-
public class NameList : INotifyPropertyChanged
-
{
-
public event PropertyChangedEventHandler PropertyChanged;
-
-
-
public NameList(string name, string jOb, string class_, int num) { Name = name; Class_ = class_; JOb = jOb; Num = num; }
-
private string name;
-
-
public string Name
-
{
-
get { return name; }
-
set
-
{
-
name = value;
-
if (PropertyChanged != null)
-
{
-
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
-
}
-
-
}
-
}
-
private int num;
-
-
public int Num
-
{
-
get { return num; }
-
set
-
{
-
num = value;
-
if (PropertyChanged != null)
-
{
-
PropertyChanged(this, new PropertyChangedEventArgs("Num"));
-
}
-
}
-
}
-
private string class_;
-
-
public string Class_
-
{
-
get { return class_; }
-
set
-
{
-
class_ = value;
-
if (PropertyChanged != null)
-
{
-
PropertyChanged(this, new PropertyChangedEventArgs("Class_"));
-
}
-
}
-
}
-
-
-
-
private string jOb;
-
-
public string JOb
-
{
-
get { return jOb; }
-
set
-
{
-
jOb = value;
-
if (PropertyChanged != null)
-
{
-
PropertyChanged(this, new PropertyChangedEventArgs("JOb"));
-
}
-
}
-
}
-
-
-
}
-
-
}
WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据的更多相关文章
- WPF DataGrid row background converter datagrid 行背景随绑定数据变化,转换器
<DataGrid Grid.Row=" ItemsSource="{Binding SalesList,UpdateSourceTrigger=PropertyChange ...
- WPF (DataGridColumnHeader)实现自义定列头样式 并绑定数据
原文:WPF (DataGridColumnHeader)实现自义定列头样式 并绑定数据 实现功能是这样的 自定义列头 样式 样式里的 数据来源于后台绑定 这篇就说头样式 和头样式数据绑定 思路 1) ...
- WPF ListView点击删除某一行并获取绑定数据
最近在开发WPF程序时遇到一个问题,在gridview中希望实现在每一行最后添加一个删除的按钮,但是发现点击每行的button时只会触发button的点击事件,并没有选中这一行,此时调用list.Se ...
- WPF Datagrid 动态生成列 并绑定数据
原文:WPF Datagrid 动态生成列 并绑定数据 说的是这里 因为列头是动态加载的 (后台for循环 一会能看到代码) 数据来源于左侧列 左侧列数据源 当然num1 属于临时的dome使用 可 ...
- WPF 4 DataGrid 控件(自定义样式篇)
原文:WPF 4 DataGrid 控件(自定义样式篇) 在<WPF 4 DataGrid 控件(基本功能篇)>中我们已经学习了DataGrid 的基本功能及使用方法.本篇将继续 ...
- 打造自定Select样式
打造自定Select样式 我们为什么要自定义select样式? 1.select最大的一个缺陷就是不能自定义下拉按钮的样式. 效果图: 在线演示地址: http://www.smallui.com/j ...
- WPF后台设置xaml控件的样式System.Windows.Style
WPF后台设置xaml控件的样式System.Windows.Style 摘-自 :感谢 作者: IT小兵 http://3w.suchso.com/projecteac-tual/wpf-zhi ...
- C# DevExpress_gridControl 行号行样式
#region 行号 /// <summary> /// 行号 /// </summary> /// <param name="sender"> ...
- WPF界面设计技巧(10)-样式的继承
原文:WPF界面设计技巧(10)-样式的继承 PS:现在我的MailMail完工了,进入内测阶段了,终于可以腾出手来写写教程了哈,关于MailMail的介绍及内测程序索取:http://www.cnb ...
随机推荐
- Redis面试篇 -- 如何保证缓存与数据库的双写一致性?
如果不是严格要求“缓存和数据库”必须保证一致性的话,最好不要做这个方案:即 读请求和写请求串行化,串到一个内存队列里面去.串行化可以保证一定不会出现不一致的情况,但会导致系统吞吐量大幅度降低. 解决这 ...
- ling to sql创建临时变量 let的使用
使用let赋值给临时变量 var dailys = from f in _postgreDbContext.draws let temp = f.review_time.Value.Date wher ...
- C lang: Pointer
Ax_Terminology xa_pointer pointer is the address used to store the variable;A variable (or data obje ...
- VM虚拟机安装无法将值写入注册表.....请确认你是否有足够的权限访问该注册表项,或者与技术支持人员联系。
解决方法: 关掉360安全卫士等软件再安装
- 第十六届浙江大学宁波理工学院程序设计大赛 D 雷顿女士与分队hard version(dp)
题意 链接:https://ac.nowcoder.com/acm/contest/2995/D来源:牛客网 卡特莉接到来自某程序设计竞赛集训队的邀请,来为他们进行分队规划. 现在集训队共有n名选手, ...
- windows和linux下查看java安装路径
windows下查看版本:(默认安装路径安装就不需要去配环境变量了) java -version windows下查看安装路径: java -verbose Linux下安装版本查看方式和window ...
- 07. Go 语言接口
Go 语言接口 接口本身是调用方和实现方均需要遵守的一种协议,大家按照统一的方法命名参数类型和数量来协调逻辑处理的过程. Go 语言中使用组合实现对象特性的描述.对象的内部使用结构体内嵌组合对象应该具 ...
- if(response.isSuccess){}else{}的方式,如果我们由于忽略没有设置success字段的值,就可能导致
在日常开发中,我们会经常要在类中定义布尔类型的变量,比如在给外部系统提供一个RPC接口的时候,我们一般会定义一个字段表示本次请求是否成功的. 关于这个”本次请求是否成功”的字段的定义,其实是有很多种讲 ...
- 一、I/O模型之BIO
I/O模型之BIO 基本介绍 Java BIO 就是传统的 Java IO 编程,其相关的类和接口再 java.io 包下 BIO(blocking I/O):同步阻塞,服务器实现模式为一个连接一个线 ...
- C语言结构选择语句
总结一下常用的if else与switch,其中switch中的break知识点是笔试题经常考到的内容. if else与else if 在C语言中,经常使用if else选择语句,来实现很多对应的功 ...