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

2021-01-23 10:14

阅读:721

标签:cti   handler   lse   framework   val   property   姓名   temp   window   

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

 

技术图片

功能阐述 

就上面那图片

刚开始 考虑使用 RowHeaderTemplate 来实现  发现总绑定不上数据  上官网查了一下 

 

技术图片

技术图片不支持上下文绑定  fffffffffffff

只能考虑样式了  经验不足 经验不足~

直接上前后台源码了

XAML

  1. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="WpfApplication31.MainWindow"
  4. Title="MainWindow" Height="350" Width="525">
  5. "Template">
  6. "{x:Type DataGridRowHeader}">
  7. "59.834" Width="207.908">
  8. "20*"/>
  9. "21*"/>
  10. "77*"/>
  11. "2" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch">
  12. "Stretch" Height="Auto" Margin="0" Grid.Row="1" VerticalAlignment="Stretch">
  13. "#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
  14. "#FFBFBFBF" BorderThickness="0,0,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
  15. "#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="0" Margin="0">
  16. "#FFBFBFBF" BorderThickness="1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" Margin="0" VerticalAlignment="Stretch" Width="Auto" Background="White">
  17. "#FFBFBFBF" BorderThickness="0,1,1,1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto" Background="White" Grid.Column="1">
  18. "dataGrid" CanUserAddRows = "false" AutoGenerateColumns="False" Margin="10,10,0,0" RowHeaderStyle="{DynamicResource DataGridRowHeaderStyle1}" >
  19. "姓名" Binding="{Binding Name}"/>
  20. "年龄" Binding="{Binding Class_}"/>
  21. 后台代码  

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections.ObjectModel;
    4. using System.ComponentModel;
    5. using System.Data;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Windows;
    9. using System.Windows.Controls;
    10. using System.Windows.Data;
    11. using System.Windows.Documents;
    12. using System.Windows.Input;
    13. using System.Windows.Media;
    14. using System.Windows.Media.Imaging;
    15. using System.Windows.Navigation;
    16. using System.Windows.Shapes;
    17. namespace WpfApplication31
    18. {
    19. ///
    20. /// MainWindow.xaml 的交互逻辑
    21. ///
    22. public partial class MainWindow : Window
    23. {
    24. public MainWindow()
    25. {
    26. InitializeComponent();
    27. dataGrid.ItemsSource = GetNameData();
    28. }
    29. ObservableCollection listName = new ObservableCollection();
    30. private ObservableCollectionGetNameData()
    31. {
    32. listName.Add(new NameList("市川 賞子", "リーダー", "B", 1));
    33. listName.Add(new NameList("石田", "リーダー", "C", 2));
    34. listName.Add(new NameList("安达 鮎美", "リーダー", "C", 3));
    35. return listName;
    36. }
    37. }
    38. public class NameList : INotifyPropertyChanged
    39. {
    40. public event PropertyChangedEventHandler PropertyChanged;
    41. public NameList(string name, string jOb, string class_, int num) { Name = name; Class_ = class_; JOb = jOb; Num = num; }
    42. private string name;
    43. public string Name
    44. {
    45. get { return name; }
    46. set
    47. {
    48. name = value;
    49. if (PropertyChanged != null)
    50. {
    51. PropertyChanged(this, new PropertyChangedEventArgs("Name"));
    52. }
    53. }
    54. }
    55. private int num;
    56. public int Num
    57. {
    58. get { return num; }
    59. set
    60. {
    61. num = value;
    62. if (PropertyChanged != null)
    63. {
    64. PropertyChanged(this, new PropertyChangedEventArgs("Num"));
    65. }
    66. }
    67. }
    68. private string class_;
    69. public string Class_
    70. {
    71. get { return class_; }
    72. set
    73. {
    74. class_ = value;
    75. if (PropertyChanged != null)
    76. {
    77. PropertyChanged(this, new PropertyChangedEventArgs("Class_"));
    78. }
    79. }
    80. }
    81. private string jOb;
    82. public string JOb
    83. {
    84. get { return jOb; }
    85. set
    86. {
    87. jOb = value;
    88. if (PropertyChanged != null)
    89. {
    90. PropertyChanged(this, new PropertyChangedEventArgs("JOb"));
    91. }
    92. }
    93. }
    94. }
    95. }

      

     

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

    标签:cti   handler   lse   framework   val   property   姓名   temp   window   

    原文地址:https://www.cnblogs.com/lonelyxmas/p/12075388.html


评论


亲,登录后才可以留言!

推荐文章

最新文章

置顶文章