由于项目要显示表头合并,而数据源列随时变更,又不想重复的画表格,就实现动态数据(dynamic)绑定和配置数据列模板的方式

编辑DataGridColumnHeader样式实现表头合并:效果如下

实现思路:

在表头中插入一个Grid,Grid列跟HeaderColmun列数相等,并关联HeaderColmun的SizeChanged事件,Colmun列大小发生变化时,合并的头模板也会跟着移动。

  1. <Grid x:Name="PART_ColumnHeadersPresenter_Grid"
  2. Height=""
  3. ShowGridLines="False">
  4. </Grid>
  1. Dictionary<DataGridColumnHeader, ColumnDefinition> dictCols = new Dictionary<DataGridColumnHeader, ColumnDefinition>();
  2.  
  3. private void DataGridTitleSpan_Loaded(object sender, RoutedEventArgs e)
  4. {
  5. var hdCols = WPFVisualTreeHelper.GetChildByName<DataGridColumnHeadersPresenter>(this, "PART_ColumnHeadersPresenter");
  6. var grid = WPFVisualTreeHelper.GetChildByName<Grid>(this, "PART_ColumnHeadersPresenter_Grid");
  7. if (grid == null)
  8. {
  9. return;
  10. }
  11. //grid.Visibility = Visibility.Collapsed;
  12. //if (DataSouceGridHeaderColTemplate == null || DataSouceGridHeaderColTemplate.Count == 0)
  13. //{
  14. // grid.Visibility = Visibility.Collapsed;
  15. //}
  16. var hdItem = WPFVisualTreeHelper.FindVisualChild<DataGridCellsPanel>(hdCols);
  17. var header = hdItem.FirstOrDefault();
  18. if (header != null)
  19. {
  20. foreach (var item in header.Children)
  21. {
  22. var vHd = item as DataGridColumnHeader;
  23. vHd.SizeChanged += VHd_SizeChanged;
  24. ColumnDefinition rd = new ColumnDefinition();
  25. rd.Width = new GridLength(vHd.ActualWidth, GridUnitType.Pixel);
  26. grid.ColumnDefinitions.Add(rd);
  27. dictCols[vHd] = rd;
  28. }
  29. }
  30. GenerateHeader(DataSouceGridHeaderColTemplate, grid);
  31. }
  32.  
  33. private void VHd_SizeChanged(object sender, SizeChangedEventArgs e)
  34. {
  35. var vHd = sender as DataGridColumnHeader;
  36. if (dictCols.ContainsKey(vHd))
  37. {
  38. dictCols[vHd].Width = new GridLength(vHd.ActualWidth, GridUnitType.Pixel);
  39. }
  40. }

下面是完整的HeaderColmun列模板

  1. <Style x:Key="DataGridColumnHeaderStyle_Colspan"
  2. TargetType="{x:Type DataGridColumnHeader}">
  3. <Setter Property="VerticalContentAlignment"
  4. Value="Center" />
  5. <Setter Property="Template">
  6. <Setter.Value>
  7. <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
  8. <!--<Grid>
  9. <Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}"
  10. BorderThickness="{TemplateBinding BorderThickness}"
  11. Background="{TemplateBinding Background}"
  12. IsClickable="{TemplateBinding CanUserSort}"
  13. IsPressed="{TemplateBinding IsPressed}"
  14. IsHovered="{TemplateBinding IsMouseOver}"
  15. Padding="{TemplateBinding Padding}"
  16. SortDirection="{TemplateBinding SortDirection}"
  17. SeparatorBrush="{TemplateBinding SeparatorBrush}"
  18. SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
  19. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  20. RecognizesAccessKey="True"
  21. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  22. VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  23. </Themes:DataGridHeaderBorder>
  24. <Thumb x:Name="PART_LeftHeaderGripper"
  25. HorizontalAlignment="Left"
  26. Style="{StaticResource ColumnHeaderGripperStyle}" />
  27. <Thumb x:Name="PART_RightHeaderGripper"
  28. HorizontalAlignment="Right"
  29. Style="{StaticResource ColumnHeaderGripperStyle}" />
  30. </Grid>-->
  31. <Grid>
  32. <Grid.RowDefinitions>
  33. <RowDefinition Height="Auto"></RowDefinition>
  34. <RowDefinition Height="*"></RowDefinition>
  35. </Grid.RowDefinitions>
  36. <Border BorderBrush="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  37. Padding="{TemplateBinding Padding}"
  38. BorderThickness="0 0 0 1"
  39. Grid.Row=""
  40. Visibility="{Binding Path=ColspanVisibility,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
  41. <Grid x:Name="PART_ColumnHeadersPresenter_Grid"
  42. Height=""
  43. ShowGridLines="False">
  44. </Grid>
  45. </Border>
  46. <Grid Grid.Row="">
  47. <Themes:DataGridHeaderBorder BorderBrush="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  48. BorderThickness="0 0 1 1"
  49. Background="Transparent"
  50. IsClickable="{TemplateBinding CanUserSort}"
  51. IsPressed="{TemplateBinding IsPressed}"
  52. IsHovered="{TemplateBinding IsMouseOver}"
  53. Padding="{TemplateBinding Padding}"
  54. SortDirection="{TemplateBinding SortDirection}"
  55. SeparatorBrush="{TemplateBinding SeparatorBrush}"
  56. SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
  57. <ContentPresenter HorizontalAlignment="{Binding HorizontalContentAlignment,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  58. RecognizesAccessKey="True"
  59. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  60. VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  61. </Themes:DataGridHeaderBorder>
  62. <Thumb x:Name="PART_LeftHeaderGripper"
  63. HorizontalAlignment="Left"
  64. Style="{StaticResource ColumnHeaderGripperStyle}" />
  65. <Thumb x:Name="PART_RightHeaderGripper"
  66. HorizontalAlignment="Right"
  67. Style="{StaticResource ColumnHeaderGripperStyle}" />
  68. </Grid>
  69. </Grid>
  70. </ControlTemplate>
  71. </Setter.Value>
  72. </Setter>
  73. </Style>

关键代码如下:

显示的View Xaml和Code

  1. <UserControl x:Class="YunTong46View.Usr_TestDataGridTableView"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:YunTong46View"
  7. mc:Ignorable="d"
  8. d:DesignHeight=""
  9. d:DesignWidth="">
  10. <UserControl.Resources>
  11. <ResourceDictionary Source="Themes/DataGridStyle.xaml">
  12. </ResourceDictionary>
  13. </UserControl.Resources>
  14. <StackPanel>
  15. <StackPanel Margin="20 15 20 10">
  16. <TextBlock Text="出现滚动条:数据绑定"
  17. Foreground="Red"
  18. FontSize=""></TextBlock>
  19. <local:DataGridTitleSpan x:Name="dataGridTitle2"
  20. Width=""
  21. Height=""
  22. VerticalAlignment="Top"
  23. HorizontalAlignment="Left"
  24. ScrollViewer.HorizontalScrollBarVisibility="Visible"
  25. ScrollViewer.VerticalScrollBarVisibility="Visible"
  26. DataSouceGridHeaderColTemplate="{Binding Headers0}"
  27. ItemsSource="{Binding DataSource}">
  28. </local:DataGridTitleSpan>
  29. </StackPanel>
  30. <StackPanel Margin="20 10">
  31. <TextBlock Text="dynamic动态类数据绑定不支持排序"
  32. Foreground="Red"
  33. FontSize=""></TextBlock>
  34. <local:DataGridTitleSpan x:Name="dataGridTitle"
  35. Height=""
  36. ScrollViewer.HorizontalScrollBarVisibility="Visible"
  37. ScrollViewer.VerticalScrollBarVisibility="Visible"
  38. DataSouceGridHeaderColTemplate="{Binding Headers0}">
  39. </local:DataGridTitleSpan>
  40. </StackPanel>
  41.  
  42. <StackPanel Margin="20 10">
  43. <TextBlock Text="引用样式"
  44. Foreground="Red"
  45. FontSize=""></TextBlock>
  46. <DataGrid x:Name="dataGrid"
  47. Height=""
  48. Style="{DynamicResource DataGridStyle_Colspan}"
  49. ItemsSource="{Binding DataSource}"
  50. Visibility="Visible">
  51. </DataGrid>
  52. </StackPanel>
  53.  
  54. <StackPanel Margin="20 10">
  55. <TextBlock Text="原生DataGrid"
  56. Foreground="Red"
  57. FontSize=""></TextBlock>
  58. <DataGrid x:Name="dataGrid2"
  59. Height=""
  60. BorderBrush="Blue"
  61. AutoGenerateColumns="False"
  62. HorizontalGridLinesBrush="Blue"
  63. VerticalGridLinesBrush="Blue"
  64. ItemsSource="{Binding DataSource}">
  65. </DataGrid>
  66. </StackPanel>
  67. </StackPanel>
  68. </UserControl>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace YunTong46View
  17. {
  18. /// <summary>
  19. /// Usr_YunTong46MainView.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class Usr_TestDataGridTableView : UserControl
  22. {
  23. ViewMode viewMode = new ViewMode();
  24. public Usr_TestDataGridTableView()
  25. {
  26. InitializeComponent();
  27. viewMode.Init();
  28. this.DataContext = viewMode;
  29. SetHeaderTemplates(dataGridTitle, viewMode.Headers1);
  30. SetHeaderTemplates(dataGridTitle2, viewMode.Headers1);
  31. SetHeaderTemplates(dataGrid, viewMode.Headers1);
  32. SetHeaderTemplates(dataGrid2, viewMode.Headers1);
  33. this.Loaded += Usr_YunTong46MainView_Loaded;
  34. }
  35.  
  36. private void Usr_YunTong46MainView_Loaded(object sender, RoutedEventArgs e)
  37. {
  38. var json = JsonHelper.SerializeObject(viewMode.DataSource);
  39. var dyDatas = JsonHelper.DeserializeObject<dynamic>(json);
  40. dataGridTitle.ItemsSource = dyDatas;
  41. }
  42.  
  43. private void SetHeaderTemplates(DataGrid dataGrid, List<HeaderTemplate> headers)
  44. {
  45. foreach (var item in headers)
  46. {
  47. var col = new DataGridTextColumn();
  48. col.Header = item.HeaderName;
  49. var bind = new Binding();
  50. bind.Path = new PropertyPath(item.PropertyName);
  51. if (!string.IsNullOrEmpty(item.PropertyFormat))
  52. {
  53. //bind.StringFormat = "{}{0:" + item.PropertyFormat + "}}";
  54. bind.StringFormat = item.PropertyFormat.Trim();
  55. }
  56. col.Binding = bind;
  57. DataGridLengthUnitType unType = DataGridLengthUnitType.Auto;
  58. double width = ;
  59. if (item.ColmunUnitType == "p")
  60. {
  61. unType = DataGridLengthUnitType.Pixel;
  62. width = item.ColmunWidth;
  63. }
  64. else if (item.ColmunUnitType == "s")
  65. {
  66. unType = DataGridLengthUnitType.Star;
  67. width = item.ColmunWidth;
  68. }
  69. if (width < )
  70. {
  71. width = ;
  72. }
  73. col.Width = new DataGridLength(width, unType);
  74. dataGrid.Columns.Add(col);
  75. }
  76. }
  77. }
  78. public class ViewMode
  79. {
  80. private List<HeaderTemplate> _headers0 = new List<HeaderTemplate>();
  81. private List<HeaderTemplate> _headers1 = new List<HeaderTemplate>();
  82. private List<DataModel> _dataSource = new List<DataModel>();
  83.  
  84. public List<HeaderTemplate> Headers0
  85. {
  86. get
  87. {
  88. return _headers0;
  89. }
  90.  
  91. set
  92. {
  93. _headers0 = value;
  94. }
  95. }
  96.  
  97. public List<HeaderTemplate> Headers1
  98. {
  99. get
  100. {
  101. return _headers1;
  102. }
  103.  
  104. set
  105. {
  106. _headers1 = value;
  107. }
  108. }
  109.  
  110. public List<DataModel> DataSource
  111. {
  112. get
  113. {
  114. return _dataSource;
  115. }
  116.  
  117. set
  118. {
  119. _dataSource = value;
  120. }
  121. }
  122.  
  123. public void Init()
  124. {
  125. _headers0.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , HeaderName = "故障登记时间及状态" });
  126. _headers0.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , HeaderName = "通知时间及通知方法" });
  127. _headers0.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , HeaderName = "到达时间及签名" });
  128. _headers0.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , HeaderName = "消除不良及破损后的时间和方法" });
  129.  
  130. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "GZDT", PropertyFormat = "MM-dd", ColmunUnitType = "a", ColmunWidth = , HeaderName = "月日" });
  131. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "GZDT", PropertyFormat = "HH:mm", ColmunUnitType = "a", ColmunWidth = , HeaderName = "时分" });
  132. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "GZDeviceName", ColmunUnitType = "a", ColmunWidth = , HeaderName = "设备名称" });
  133. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "GZStatus", ColmunUnitType = "a", ColmunWidth = , HeaderName = "故障状态" });
  134.  
  135. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "TZDW", ColmunUnitType = "a", ColmunWidth = , HeaderName = "通知单位" });
  136. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "TZDT", PropertyFormat = "MM-dd", ColmunUnitType = "a", ColmunWidth = , HeaderName = "月日" });
  137. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "TZDT", PropertyFormat = "HH:mm", ColmunUnitType = "a", ColmunWidth = , HeaderName = "时分" });
  138. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "TZFF", ColmunUnitType = "a", ColmunWidth = , HeaderName = "通知方法" });
  139.  
  140. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "DDDT", PropertyFormat = "MM-dd", ColmunUnitType = "a", ColmunWidth = , HeaderName = "月日" });
  141. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "DDDT", PropertyFormat = "HH:mm", ColmunUnitType = "a", ColmunWidth = , HeaderName = "时分" });
  142. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "DDQM", ColmunUnitType = "a", ColmunWidth = , HeaderName = "该段工作人员到达后签名" });
  143.  
  144. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "BLDT", PropertyFormat = "MM-dd", ColmunUnitType = "a", ColmunWidth = , HeaderName = "月日" });
  145. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "BLDT", PropertyFormat = "HH:mm", ColmunUnitType = "a", ColmunWidth = , HeaderName = "时分" });
  146. _headers1.Add(new HeaderTemplate() { ColmunIndex = , ColmunSpan = , PropertyName = "BLTEXT", ColmunUnitType = "s", ColmunWidth = , HeaderName = "破损及不良的原因,采用何种方法进行\r;修理。工作人员及车站值班员签字" });
  147.  
  148. for (int i = ; i < ; i++)
  149. {
  150. DataModel model = new DataModel();
  151. model.DDDT = DateTime.Now.AddMinutes(-);
  152. model.GZDT = model.DDDT;
  153. model.TZDT = model.DDDT;
  154. model.BLDT = model.DDDT;
  155. model.GZDeviceName = "故障设备名称" + i.ToString();
  156. model.GZStatus = "故障状态" + i.ToString();
  157. model.TZDW = "通知单位" + i.ToString();
  158. model.TZFF = "通知方法" + i.ToString();
  159. model.DDQM = "到达签名" + i.ToString();
  160. model.BLTEXT = "不良内容" + i.ToString();
  161. _dataSource.Add(model);
  162. }
  163. }
  164. }
  165.  
  166. public class DataModel
  167. {
  168. public DateTime GZDT { set; get; }
  169.  
  170. public string GZDeviceName { set; get; }
  171.  
  172. public string GZStatus { set; get; }
  173.  
  174. public DateTime TZDT { set; get; }
  175.  
  176. public string TZDW { set; get; }
  177.  
  178. public string TZFF { set; get; }
  179.  
  180. /// <summary>
  181. /// 到达时间
  182. /// </summary>
  183. public DateTime DDDT { set; get; }
  184.  
  185. public string DDQM { set; get; }
  186.  
  187. public DateTime BLDT { set; get; }
  188.  
  189. public string BLTEXT { set; get; }
  190. }
  191. }

DataTable样式和Code

  1. <ResourceDictionary 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">
  4. <Style x:Key="DataGridRowStyle_ColSpan"
  5. TargetType="{x:Type DataGridRow}">
  6. <Setter Property="Background"
  7. Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
  8. <Setter Property="SnapsToDevicePixels"
  9. Value="true" />
  10. <Setter Property="Validation.ErrorTemplate"
  11. Value="{x:Null}" />
  12. <Setter Property="ValidationErrorTemplate">
  13. <Setter.Value>
  14. <ControlTemplate>
  15. <TextBlock Foreground="Red"
  16. Margin="2,0,0,0"
  17. Text="!"
  18. VerticalAlignment="Center" />
  19. </ControlTemplate>
  20. </Setter.Value>
  21. </Setter>
  22. <Setter Property="Template">
  23. <Setter.Value>
  24. <ControlTemplate TargetType="{x:Type DataGridRow}">
  25. <Border x:Name="DGR_Border"
  26. BorderBrush="{TemplateBinding BorderBrush}"
  27. BorderThickness="{TemplateBinding BorderThickness}"
  28. Background="{TemplateBinding Background}"
  29. SnapsToDevicePixels="True">
  30. <SelectiveScrollingGrid>
  31. <SelectiveScrollingGrid.ColumnDefinitions>
  32. <ColumnDefinition Width="Auto" />
  33. <ColumnDefinition Width="*" />
  34. </SelectiveScrollingGrid.ColumnDefinitions>
  35. <SelectiveScrollingGrid.RowDefinitions>
  36. <RowDefinition Height="*" />
  37. <RowDefinition Height="Auto" />
  38. </SelectiveScrollingGrid.RowDefinitions>
  39. <Border Grid.Column=""
  40. BorderThickness="1 0 0 0"
  41. BorderBrush="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}">
  42. <DataGridCellsPresenter ItemsPanel="{TemplateBinding ItemsPanel}"
  43. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  44. </Border>
  45. <DataGridDetailsPresenter Grid.Column=""
  46. Grid.Row=""
  47. SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
  48. Visibility="{TemplateBinding DetailsVisibility}" />
  49. <!--隐藏左侧行号-->
  50. <DataGridRowHeader Grid.RowSpan=""
  51. SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
  52. Visibility="Collapsed" />
  53. </SelectiveScrollingGrid>
  54. </Border>
  55. </ControlTemplate>
  56. </Setter.Value>
  57. </Setter>
  58. <Style.Triggers>
  59. <Trigger Property="IsNewItem"
  60. Value="True">
  61. <Setter Property="Margin"
  62. Value="{Binding NewItemMargin, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
  63. </Trigger>
  64. <Trigger Property="IsSelected"
  65. Value="True">
  66. <Setter Property="Background"
  67. Value="#FFE8C91A" />
  68. <Setter Property="Foreground"
  69. Value="Red" />
  70. </Trigger>
  71. </Style.Triggers>
  72. </Style>
  73. <Style x:Key="DataGridCellStyle_Colspan"
  74. TargetType="{x:Type DataGridCell}">
  75. <Setter Property="FontSize"
  76. Value="" />
  77. <Setter Property="HorizontalContentAlignment"
  78. Value="Center"></Setter>
  79. <Setter Property="Template">
  80. <Setter.Value>
  81. <ControlTemplate TargetType="{x:Type DataGridCell}">
  82. <!--<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  83. VerticalAlignment="Center"
  84. HorizontalAlignment="Center" />-->
  85. <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  86.  
  87. </ControlTemplate>
  88. </Setter.Value>
  89. </Setter>
  90. <!--<Style.Triggers>
  91. <Trigger Property="IsSelected"
  92. Value="True">
  93. <Setter Property="Background"
  94. Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
  95. <Setter Property="Foreground"
  96. Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
  97. <Setter Property="BorderBrush"
  98. Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
  99. </Trigger>
  100. <Trigger Property="IsMouseOver"
  101. Value="True">
  102. <Setter Property="Background"
  103. Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
  104. </Trigger>
  105. <Trigger Property="IsKeyboardFocusWithin"
  106. Value="True">
  107. <Setter Property="BorderBrush"
  108. Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}" />
  109. </Trigger>
  110. <Trigger Property="IsSelected"
  111. Value="True">
  112. <Setter Property="Foreground"
  113. Value="Black" />
  114. </Trigger>
  115. </Style.Triggers>-->
  116. </Style>
  117. <BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" />
  118. <!--<Style x:Key="RowHeaderGripperStyle"
  119. TargetType="{x:Type Thumb}">
  120. <Setter Property="Height"
  121. Value="" />
  122. <Setter Property="Background"
  123. Value="Transparent" />
  124. <Setter Property="Cursor"
  125. Value="SizeNS" />
  126. <Setter Property="Template">
  127. <Setter.Value>
  128. <ControlTemplate TargetType="{x:Type Thumb}">
  129. <Border Background="{TemplateBinding Background}"
  130. Padding="{TemplateBinding Padding}" />
  131. </ControlTemplate>
  132. </Setter.Value>
  133. </Setter>
  134. </Style>-->
  135. <Style x:Key="DataGridRowHeaderStyle_Colspan"
  136. TargetType="{x:Type DataGridRowHeader}">
  137. <Setter Property="Template">
  138. <Setter.Value>
  139. <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
  140. <Grid>
  141. <Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}"
  142. BorderThickness="{TemplateBinding BorderThickness}"
  143. Background="{TemplateBinding Background}"
  144. IsPressed="{TemplateBinding IsPressed}"
  145. IsHovered="{TemplateBinding IsMouseOver}"
  146. IsSelected="{TemplateBinding IsRowSelected}"
  147. Orientation="Horizontal"
  148. Padding="{TemplateBinding Padding}"
  149. SeparatorBrush="{TemplateBinding SeparatorBrush}"
  150. SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
  151. <StackPanel Orientation="Horizontal">
  152. <ContentPresenter RecognizesAccessKey="True"
  153. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  154. VerticalAlignment="Center" />
  155. <Control SnapsToDevicePixels="false"
  156. Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"
  157. Visibility="{Binding (Validation.HasError), Converter={StaticResource bool2VisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" />
  158. </StackPanel>
  159. </Themes:DataGridHeaderBorder>
  160. <!--<Thumb x:Name="PART_TopHeaderGripper"
  161. Style="{StaticResource RowHeaderGripperStyle}"
  162. VerticalAlignment="Top" />
  163. <Thumb x:Name="PART_BottomHeaderGripper"
  164. Style="{StaticResource RowHeaderGripperStyle}"
  165. VerticalAlignment="Bottom" />-->
  166. </Grid>
  167. </ControlTemplate>
  168. </Setter.Value>
  169. </Setter>
  170. </Style>
  171. <Style x:Key="ColumnHeaderGripperStyle"
  172. TargetType="{x:Type Thumb}">
  173. <Setter Property="Width"
  174. Value="" />
  175. <Setter Property="Background"
  176. Value="Transparent" />
  177. <Setter Property="Cursor"
  178. Value="SizeWE" />
  179. <Setter Property="Template">
  180. <Setter.Value>
  181. <ControlTemplate TargetType="{x:Type Thumb}">
  182. <Border Background="{TemplateBinding Background}"
  183. Padding="{TemplateBinding Padding}" />
  184. </ControlTemplate>
  185. </Setter.Value>
  186. </Setter>
  187. </Style>
  188. <Style x:Key="DataGridColumnHeaderStyle_Colspan"
  189. TargetType="{x:Type DataGridColumnHeader}">
  190. <Setter Property="VerticalContentAlignment"
  191. Value="Center" />
  192. <Setter Property="Template">
  193. <Setter.Value>
  194. <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
  195. <!--<Grid>
  196. <Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}"
  197. BorderThickness="{TemplateBinding BorderThickness}"
  198. Background="{TemplateBinding Background}"
  199. IsClickable="{TemplateBinding CanUserSort}"
  200. IsPressed="{TemplateBinding IsPressed}"
  201. IsHovered="{TemplateBinding IsMouseOver}"
  202. Padding="{TemplateBinding Padding}"
  203. SortDirection="{TemplateBinding SortDirection}"
  204. SeparatorBrush="{TemplateBinding SeparatorBrush}"
  205. SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
  206. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  207. RecognizesAccessKey="True"
  208. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  209. VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  210. </Themes:DataGridHeaderBorder>
  211. <Thumb x:Name="PART_LeftHeaderGripper"
  212. HorizontalAlignment="Left"
  213. Style="{StaticResource ColumnHeaderGripperStyle}" />
  214. <Thumb x:Name="PART_RightHeaderGripper"
  215. HorizontalAlignment="Right"
  216. Style="{StaticResource ColumnHeaderGripperStyle}" />
  217. </Grid>-->
  218. <Grid>
  219. <Grid.RowDefinitions>
  220. <RowDefinition Height="Auto"></RowDefinition>
  221. <RowDefinition Height="*"></RowDefinition>
  222. </Grid.RowDefinitions>
  223. <Border BorderBrush="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  224. Padding="{TemplateBinding Padding}"
  225. BorderThickness="0 0 0 1"
  226. Grid.Row=""
  227. Visibility="{Binding Path=ColspanVisibility,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
  228. <Grid x:Name="PART_ColumnHeadersPresenter_Grid"
  229. Height=""
  230. ShowGridLines="False">
  231. </Grid>
  232. </Border>
  233. <Grid Grid.Row="">
  234. <Themes:DataGridHeaderBorder BorderBrush="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  235. BorderThickness="0 0 1 1"
  236. Background="Transparent"
  237. IsClickable="{TemplateBinding CanUserSort}"
  238. IsPressed="{TemplateBinding IsPressed}"
  239. IsHovered="{TemplateBinding IsMouseOver}"
  240. Padding="{TemplateBinding Padding}"
  241. SortDirection="{TemplateBinding SortDirection}"
  242. SeparatorBrush="{TemplateBinding SeparatorBrush}"
  243. SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
  244. <ContentPresenter HorizontalAlignment="{Binding HorizontalContentAlignment,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}"
  245. RecognizesAccessKey="True"
  246. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  247. VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  248. </Themes:DataGridHeaderBorder>
  249. <Thumb x:Name="PART_LeftHeaderGripper"
  250. HorizontalAlignment="Left"
  251. Style="{StaticResource ColumnHeaderGripperStyle}" />
  252. <Thumb x:Name="PART_RightHeaderGripper"
  253. HorizontalAlignment="Right"
  254. Style="{StaticResource ColumnHeaderGripperStyle}" />
  255. </Grid>
  256. </Grid>
  257. </ControlTemplate>
  258. </Setter.Value>
  259. </Setter>
  260. </Style>
  261. <Style x:Key="DataGridStyle_Colspan"
  262. TargetType="{x:Type DataGrid}">
  263. <Setter Property="Background"
  264. Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
  265. <Setter Property="Foreground"
  266. Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
  267. <Setter Property="BorderBrush"
  268. Value="#FF688CAF" />
  269. <Setter Property="HorizontalContentAlignment"
  270. Value="Center"></Setter>
  271. <Setter Property="BorderThickness"
  272. Value="" />
  273. <Setter Property="RowDetailsVisibilityMode"
  274. Value="VisibleWhenSelected" />
  275. <Setter Property="ScrollViewer.CanContentScroll"
  276. Value="true" />
  277. <Setter Property="ScrollViewer.PanningMode"
  278. Value="Both" />
  279. <Setter Property="Stylus.IsFlicksEnabled"
  280. Value="False" />
  281. <Setter Property="CanUserAddRows"
  282. Value="False" />
  283. <Setter Property="BorderBrush"
  284. Value="Blue">
  285. </Setter>
  286. <Setter Property="HorizontalGridLinesBrush"
  287. Value="Blue">
  288. </Setter>
  289. <Setter Property="VerticalGridLinesBrush"
  290. Value="Blue">
  291. </Setter>
  292. <Setter Property="AutoGenerateColumns"
  293. Value="False">
  294. </Setter>
  295. <Setter Property="TextBlock.TextAlignment"
  296. Value="Center">
  297. </Setter>
  298. <Setter Property="RowHeaderStyle"
  299. Value="{StaticResource DataGridRowHeaderStyle_Colspan}">
  300. </Setter>
  301. <Setter Property="RowStyle"
  302. Value="{StaticResource DataGridRowStyle_ColSpan}">
  303. </Setter>
  304. <Setter Property="ColumnHeaderStyle"
  305. Value="{StaticResource DataGridColumnHeaderStyle_Colspan}">
  306. </Setter>
  307. <Setter Property="CellStyle"
  308. Value="{StaticResource DataGridCellStyle_Colspan}">
  309. </Setter>
  310. <Setter Property="Template">
  311. <Setter.Value>
  312. <ControlTemplate TargetType="{x:Type DataGrid}">
  313. <Border BorderBrush="{TemplateBinding BorderBrush}"
  314. Background="{TemplateBinding Background}"
  315. Padding="{TemplateBinding Padding}"
  316. SnapsToDevicePixels="True"
  317. x:Name="bd_Out">
  318. <ScrollViewer x:Name="DG_ScrollViewer"
  319. Focusable="false">
  320. <ScrollViewer.Template>
  321. <ControlTemplate TargetType="{x:Type ScrollViewer}">
  322. <Grid>
  323. <Grid.ColumnDefinitions>
  324. <ColumnDefinition Width="Auto" />
  325. <ColumnDefinition Width="*" />
  326. <ColumnDefinition Width="Auto" />
  327. </Grid.ColumnDefinitions>
  328. <Grid.RowDefinitions>
  329. <RowDefinition Height="Auto" />
  330. <RowDefinition Height="*" />
  331. <RowDefinition Height="Auto" />
  332. </Grid.RowDefinitions>
  333. <Button Command="{x:Static DataGrid.SelectAllCommand}"
  334. Focusable="false"
  335. Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}"
  336. Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
  337. Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
  338. <Border BorderThickness="1 1 1 0"
  339. Margin="-1 0 0 0"
  340. BorderBrush="{Binding BorderBrush,ElementName=bd_Out}"
  341. Grid.Column="">
  342. <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter"
  343. Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
  344. </Border>
  345. <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
  346. CanContentScroll="{TemplateBinding CanContentScroll}"
  347. Grid.ColumnSpan=""
  348. Grid.Row="" />
  349. <ScrollBar x:Name="PART_VerticalScrollBar"
  350. Grid.Column=""
  351. Maximum="{TemplateBinding ScrollableHeight}"
  352. Orientation="Vertical"
  353. Grid.Row=""
  354. Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
  355. Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
  356. ViewportSize="{TemplateBinding ViewportHeight}" />
  357. <Grid Grid.Column=""
  358. Grid.Row="">
  359. <Grid.ColumnDefinitions>
  360. <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
  361. <ColumnDefinition Width="*" />
  362. </Grid.ColumnDefinitions>
  363. <ScrollBar x:Name="PART_HorizontalScrollBar"
  364. Grid.Column=""
  365. Maximum="{TemplateBinding ScrollableWidth}"
  366. Orientation="Horizontal"
  367. Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
  368. Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
  369. ViewportSize="{TemplateBinding ViewportWidth}" />
  370. </Grid>
  371. </Grid>
  372. </ControlTemplate>
  373. </ScrollViewer.Template>
  374. <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  375. </ScrollViewer>
  376. </Border>
  377. </ControlTemplate>
  378. </Setter.Value>
  379. </Setter>
  380. <Style.Triggers>
  381. <MultiTrigger>
  382. <MultiTrigger.Conditions>
  383. <Condition Property="IsGrouping"
  384. Value="true" />
  385. <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping"
  386. Value="false" />
  387. </MultiTrigger.Conditions>
  388. <Setter Property="ScrollViewer.CanContentScroll"
  389. Value="false" />
  390. </MultiTrigger>
  391. </Style.Triggers>
  392. </Style>
  393. </ResourceDictionary>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Controls.Primitives;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16.  
  17. namespace YunTong46View
  18. {
  19. /// <summary>
  20. /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
  21. ///
  22. /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
  23. /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
  24. /// 元素中:
  25. ///
  26. /// xmlns:MyNamespace="clr-namespace:YunTong46View"
  27. ///
  28. ///
  29. /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
  30. /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
  31. /// 元素中:
  32. ///
  33. /// xmlns:MyNamespace="clr-namespace:YunTong46View;assembly=YunTong46View"
  34. ///
  35. /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
  36. /// 并重新生成以避免编译错误:
  37. ///
  38. /// 在解决方案资源管理器中右击目标项目,然后依次单击
  39. /// “添加引用”->“项目”->[浏览查找并选择此项目]
  40. ///
  41. ///
  42. /// 步骤 2)
  43. /// 继续操作并在 XAML 文件中使用控件。
  44. ///
  45. /// <MyNamespace:DataGridTitleSpan/>
  46. ///
  47. /// </summary>
  48. public class DataGridTitleSpan : DataGrid
  49. {
  50. ResourceDictionary rs = new ResourceDictionary();
  51. static DataGridTitleSpan()
  52. {
  53. DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGridTitleSpan), new FrameworkPropertyMetadata(typeof(DataGridTitleSpan)));
  54. }
  55.  
  56. public DataGridTitleSpan() : base()
  57. {
  58. rs.Source = new Uri("/YunTong46View;component/Themes/DataGridStyle.xaml", UriKind.Relative);
  59. //RowHeaderStyle = rs["DataGridRowHeaderStyle_Colspan"] as Style;
  60. //RowStyle = rs["DataGridRowStyle_ColSpan"] as Style;
  61. //ColumnHeaderStyle = rs["DataGridColumnHeaderStyle_Colspan"] as Style;
  62. var style = rs["DataGridStyle_Colspan"] as Style;
  63. this.Style = style;
  64. this.Loaded += DataGridTitleSpan_Loaded;
  65. }
  66.  
  67. public List<HeaderTemplate> DataSouceGridHeaderColTemplate
  68. {
  69. get { return (List<HeaderTemplate>)GetValue(DataSouceGridHeaderColTemplateProperty); }
  70. set { SetValue(DataSouceGridHeaderColTemplateProperty, value); }
  71. }
  72.  
  73. // Using a DependencyProperty as the backing store for DataSouceGridHeaderTemplate. This enables animation, styling, binding, etc...
  74. public static readonly DependencyProperty DataSouceGridHeaderColTemplateProperty =
  75. DependencyProperty.Register("DataSouceGridHeaderColTemplate", typeof(List<HeaderTemplate>), typeof(DataGridTitleSpan), new PropertyMetadata(null));
  76.  
  77. public Visibility ColspanVisibility
  78. {
  79. get { return (Visibility)GetValue(ColspanVisibilityProperty); }
  80. set { SetValue(ColspanVisibilityProperty, value); }
  81. }
  82.  
  83. // Using a DependencyProperty as the backing store for ColspanVisibility. This enables animation, styling, binding, etc...
  84. public static readonly DependencyProperty ColspanVisibilityProperty =
  85. DependencyProperty.Register("ColspanVisibility", typeof(Visibility), typeof(DataGridTitleSpan), new PropertyMetadata(Visibility.Visible));
  86.  
  87. Dictionary<DataGridColumnHeader, ColumnDefinition> dictCols = new Dictionary<DataGridColumnHeader, ColumnDefinition>();
  88.  
  89. private void DataGridTitleSpan_Loaded(object sender, RoutedEventArgs e)
  90. {
  91. var hdCols = WPFVisualTreeHelper.GetChildByName<DataGridColumnHeadersPresenter>(this, "PART_ColumnHeadersPresenter");
  92. var grid = WPFVisualTreeHelper.GetChildByName<Grid>(this, "PART_ColumnHeadersPresenter_Grid");
  93. if (grid == null)
  94. {
  95. return;
  96. }
  97. if (DataSouceGridHeaderColTemplate == null || DataSouceGridHeaderColTemplate.Count == )
  98. {
  99. (grid.Parent as Border).Visibility = Visibility.Collapsed;
  100. //ColspanVisibility = Visibility.Collapsed;
  101. return;
  102. }
  103. var hdItem = WPFVisualTreeHelper.FindVisualChild<DataGridCellsPanel>(hdCols);
  104. var header = hdItem.FirstOrDefault();
  105. if (header != null)
  106. {
  107. foreach (var item in header.Children)
  108. {
  109. var vHd = item as DataGridColumnHeader;
  110. vHd.SizeChanged += VHd_SizeChanged;
  111. ColumnDefinition rd = new ColumnDefinition();
  112. rd.Width = new GridLength(vHd.ActualWidth, GridUnitType.Pixel);
  113. grid.ColumnDefinitions.Add(rd);
  114. dictCols[vHd] = rd;
  115. }
  116. }
  117. GenerateHeader(DataSouceGridHeaderColTemplate, grid);
  118. }
  119.  
  120. private void VHd_SizeChanged(object sender, SizeChangedEventArgs e)
  121. {
  122. var vHd = sender as DataGridColumnHeader;
  123. if (dictCols.ContainsKey(vHd))
  124. {
  125. dictCols[vHd].Width = new GridLength(vHd.ActualWidth, GridUnitType.Pixel);
  126. }
  127. }
  128.  
  129. private void GenerateHeader(List<HeaderTemplate> headers, Grid g)
  130. {
  131. int colIndex = ;
  132. for (int i = ; i < headers.Count; i++)
  133. {
  134. var col = headers[i];
  135. g.Children.Add(BigTitle(colIndex, col.ColmunSpan, col.HeaderName));
  136. colIndex += (col.ColmunSpan + col.ColmunIndex);
  137. }
  138. }
  139.  
  140. private UIElement BigTitle(int col, int colspan, string text)
  141. {
  142. var txb = new TextBlock();
  143. Border bd = new Border();
  144. bd.BorderThickness = new Thickness(, , , );
  145. bd.BorderBrush = this.BorderBrush;
  146. //bd.Background = Brushes.Red;
  147. bd.Child = txb;
  148. txb.HorizontalAlignment = HorizontalAlignment.Center;
  149. txb.VerticalAlignment = VerticalAlignment.Center;
  150. txb.Text = text;
  151. Grid.SetColumn(bd, col);
  152. if (colspan > )
  153. {
  154. Grid.SetColumnSpan(bd, colspan);
  155. }
  156. return bd;
  157. }
  158. }
  159. }

如果想修改表格颜色请设置下面三个Brush

  1. <Setter Property="BorderBrush"
  2. Value="Blue">
  3. </Setter>
  4. <Setter Property="HorizontalGridLinesBrush"
  5. Value="Blue">
  6. </Setter>
  7. <Setter Property="VerticalGridLinesBrush"
  8. Value="Blue">
  9. </Setter>
此功能有两个小问题:
1.DataGridTitleSpan_Loaded捕获了DataGrid的列,所以不能在UserControl或者window的Load事件中SetHeaderTemplates,只能再构造函数中设置列。
2.原本以为通过判断合并列的数据如果为空,那么自动隐藏Grid,但是不知道为什么不生效,只能通过依赖属性才能隐藏合并的头
  1. if (DataSouceGridHeaderColTemplate == null || DataSouceGridHeaderColTemplate.Count == )
  2. {
  3. (grid.Parent as Border).Visibility = Visibility.Collapsed;
  4. //ColspanVisibility = Visibility.Collapsed;
  5. return;
  6. }

该示例主要的目的通过HeaderTemplate模板数据的配置,实现数表格头部的合并和数据显示。

还有一种稍微复杂表格头的合并,目前是列合并,可能存在行和列同时合并,已经有思路还未验证是否可行,由于项目暂未用到不花费时间研究,园友有需要就在下方留言。

点击此处下载源码

合并行的已经实现:效果如下

WPF DataGridTable的更多相关文章

  1. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  2. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  3. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  4. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  5. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  6. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  7. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  8. MVVM模式和在WPF中的实现(一)MVVM模式简介

    MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...

  9. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

随机推荐

  1. 【[ZJOI2008]泡泡堂】

    想贪心就是反复\(hack\)自己的过程 首先这很田忌赛马,但是又不完全一样 田忌赛马保证了所有马的实力不同,因此没有平局 田忌赛马的策略是当自己最强的马比不过对方最强的马的时候,就用自己最弱的马来自 ...

  2. [USACO08JAN]Telephone Lines

    嘟嘟嘟 题意概括一下,就是在无向图上求一条1到n的路径,使路径上第k + 1大的边权尽量小. 考虑dp,令dp[i][j] 表示走到节点 i,路线上有 j 条电话线免费时,路径上最贵的电缆花费最小是多 ...

  3. [转载] Python协程从零开始到放弃

    Python协程从零开始到放弃 Web安全 作者:美丽联合安全MLSRC   2017-10-09  3,973   Author: lightless@Meili-inc Date: 2017100 ...

  4. windows环境安装docker,并下载lamp镜像

    1.PC系统:windows10专业版 2.开启Hyper-V 此电脑->右击->属性->控制面板主页->(查看方式为小图标)程序和功能->右上方启动或关闭windows ...

  5. LOG算子

    原文:http://blog.csdn.net/songzitea/article/details/12851079 背景引言 在博文差分近似图像导数算子之Laplace算子中,我们提到Laplace ...

  6. FD.io社区中国行暨未来网络技术沙龙·南京站 会议小结

    What is FD.io VPP? FD.io VPP(Fast Data Input/Output Vector Packet Processing)is a new network multi- ...

  7. 跟我一起学Linux-线程创建,类似FreeRTOS创建任务

    1.参考学习大神网址:http://blog.csdn.net/ithomer/article/details/6063067 #include<stdio.h> #include< ...

  8. 如何快速找到指定端口被哪个程序占用并释放该端口(解决bindException)

    首先打开打开任务管理器,选择性能模块,下方有打开资源监视器,或者直接搜索资源监视器 在资源监视器中点击侦听端口模块,即可看到正在使用网络端口的应用程序名和pid,如果被占用可以直接使用命令行关闭即可 ...

  9. java 网站源码 六套模版 兼容手机平板PC freemaker 静态引擎 在线编辑模版

    官网 http://www.fhadmin.org/ 系统介绍: 1.网站后台采用主流的 SSM 框架 jsp JSTL,网站后台采用freemaker静态化模版引擎生成html 2.因为是生成的ht ...

  10. iOS开发--MQTT实时处理数据

    一. MQTT 一个物联网项目中用到了MQTT协议, 可以用来做设备与软件之间的互通. MQTT: 即时通讯协议, 传输层协议 二. 常用: 1.MQTTKit(已经不维护了) 2.MQTTClien ...