WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据
标签:cti handler lse framework val property 姓名 temp window
原文:WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据
功能阐述
就上面那图片
刚开始 考虑使用 RowHeaderTemplate 来实现 发现总绑定不上数据 上官网查了一下
不支持上下文绑定 fffffffffffff
只能考虑样式了 经验不足 经验不足~
直接上前后台源码了
XAML
-
-
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">
-
-
-
-
-
-
"{x:Type DataGridRowHeader}">
-
"59.834" Width="207.908">
-
-
-
-
-
-
"2" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch">
-
-
-
-
-
"Stretch" Height="Auto" Margin="0" Grid.Row="1" VerticalAlignment="Stretch">
-
-
-
-
-
"#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
-
-
-
"#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
-
-
-
-
"#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
-
-
-
-
"#FFBFBFBF" BorderThickness="1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch" Width="Auto" Background="White">
-
-
-
"#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
-
-
-
-
-
-
-
-
-
-
-
"dataGrid" CanUserAddRows = "false" AutoGenerateColumns="False" Margin="10,10,0,0" RowHeaderStyle="{DynamicResource DataGridRowHeaderStyle1}" >
-
-
"姓名" Binding="{Binding Name}"/>
-
"年龄" Binding="{Binding Class_}"/>
-
-
-
-
-
-
后台代码
-
-
using System.Collections.Generic;
-
using System.Collections.ObjectModel;
-
using System.ComponentModel;
-
-
-
-
-
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
-
-
-
/// MainWindow.xaml 的交互逻辑
-
-
public partial class MainWindow : Window
-
-
-
-
-
dataGrid.ItemsSource = GetNameData();
-
-
ObservableCollection listName = new ObservableCollection();
-
private ObservableCollectionGetNameData()
-
-
-
-
listName.Add(new NameList("市川 賞子", "リーダー", "B", 1));
-
listName.Add(new NameList("石田", "リーダー", "C", 2));
-
listName.Add(new NameList("安达 鮎美", "リーダー", "C", 3));
-
-
-
-
-
-
-
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; }
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
-
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Num"));
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Class_"));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("JOb"));
-
-
-
-
-
-
-
-
WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据
标签:cti handler lse framework val property 姓名 temp window
原文地址:https://www.cnblogs.com/lonelyxmas/p/12075388.html
评论