Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
fixed listviewgridviewstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
chancezheng committed Mar 10, 2023
1 parent d2e020e commit c0b454d
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 121 deletions.
14 changes: 14 additions & 0 deletions CookPopularCSharpToolkit/Windows/Helpers/ResourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,19 @@ public static TResource GetResource<TResource>(string resourceKey)

return default(TResource);
}

/// <summary>
/// 根据Key获取资源
/// </summary>
/// <typeparam name="TResource"></typeparam>
/// <param name="resourceKey"></param>
/// <returns></returns>
public static TResource GetResource<TResource>(object resourceKey)
{
if (Application.Current.TryFindResource(resourceKey) is TResource resource)
return resource;

return default(TResource);
}
}
}
44 changes: 0 additions & 44 deletions CookPopularControl/Communal/Attached/DataGridViewAttached.cs

This file was deleted.

10 changes: 1 addition & 9 deletions CookPopularControl/Controls/DialogBox/DialogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,7 @@ void SetResult()
{
try
{
bool isExcute = false;
if (dialog is Windows.DialogWindow win && win.IsConfirm)
isExcute = true;
else if (dialog is DialogBox dialogBox)
isExcute = true;
else
isExcute = false;

if (isExcute)
if ((dialog is Windows.DialogWindow win && win.IsConfirm) || dialog is DialogBox)
tcs.TrySetResult(dialog.GetViewModel<IDialogResultable<TResult>>().Result);
}
catch (Exception e)
Expand Down
84 changes: 82 additions & 2 deletions CookPopularControl/Controls/ItemsControl/ListViewAssistant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System.Windows;
using CookPopularCSharpToolkit.Communal;
using CookPopularCSharpToolkit.Windows;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;



Expand All @@ -12,12 +17,87 @@
namespace CookPopularControl.Controls
{
/// <summary>
/// <see cref="ListView"/>的附加属性基类
/// 表示<see cref="GridViewColumn"/>的附加属性基类
/// </summary>
public class GridViewColumnAssistant
{
public static GridLength GetColumnMinWidth(DependencyObject obj) => (GridLength)obj.GetValue(ColumnMinWidthProperty);
public static void SetColumnMinWidth(DependencyObject obj, GridLength value) => obj.SetValue(ColumnMinWidthProperty, value);
/// <summary>
/// 标识<see cref="GridViewColumnHeader"/>列项最小宽度
/// </summary>
public static readonly DependencyProperty ColumnMinWidthProperty =
DependencyProperty.RegisterAttached("ColumnMinWidth", typeof(GridLength), typeof(GridViewColumnAssistant), new PropertyMetadata(GridLength.Auto, OnColumnMinWidthChanged));

private static void OnColumnMinWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is GridViewColumn column)
{
var defaultGridViewColumnHeaderStyle = ResourceHelper.GetResource<Style>(typeof(GridViewColumnHeader));
Style style = new Style(typeof(GridViewColumnHeader), defaultGridViewColumnHeaderStyle);
var setter = new Setter(GridViewColumnHeader.MinWidthProperty, GetColumnMinWidth(column).Value);
style.Setters.Add(setter);
column.HeaderContainerStyle = style;
}
}


public static Thickness GetColumnHeaderPadding(DependencyObject obj) => (Thickness)obj.GetValue(ColumnHeaderPaddingProperty);
internal static void SetColumnHeaderPadding(DependencyObject obj, Thickness value) => obj.SetValue(ColumnHeaderPaddingProperty, value);
/// <summary>
/// 标识<see cref="GridViewColumnHeader"/>的内边距
/// 暂时无效
/// </summary>
public static readonly DependencyProperty ColumnHeaderPaddingProperty =
DependencyProperty.RegisterAttached("ColumnHeaderPadding", typeof(Thickness), typeof(GridViewColumnAssistant), new PropertyMetadata(default(Thickness), OnColumnHeaderPaddingChanged));

private static void OnColumnHeaderPaddingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is GridViewColumn column)
{
var defaultGridViewColumnHeaderStyle = ResourceHelper.GetResource<Style>(typeof(GridViewColumnHeader));
Style style = new Style(typeof(GridViewColumnHeader), defaultGridViewColumnHeaderStyle);
var setter = new Setter(ColumnHeaderPaddingProperty, GetColumnHeaderPadding(column));
//var setter = new Setter(GridViewColumnHeader.PaddingProperty, GetColumnHeaderPadding(column));

//var setter = (Setter)style.Setters.FirstOrDefault(setter => ((Setter)setter).Property == GridViewColumnHeader.PaddingProperty)!;
//setter.Value = GetColumnHeaderPadding(column);

style.Setters.Add(setter);
column.HeaderContainerStyle = style;
}
}
}


/// <summary>
/// 表示<see cref="ListView"/>的附加属性基类
/// </summary>
public class ListViewAssistant
{
public static double GetColumnHeaderHeight(DependencyObject obj) => (double)obj.GetValue(ColumnHeaderHeightProperty);
public static void SetColumnHeaderHeight(DependencyObject obj, double value) => obj.SetValue(ColumnHeaderHeightProperty, value);
/// <summary>
/// 标识<see cref="GridViewColumnHeader"/>的标头高度
/// </summary>
public static readonly DependencyProperty ColumnHeaderHeightProperty =
DependencyProperty.RegisterAttached("ColumnHeaderHeight", typeof(double), typeof(ListViewAssistant), new PropertyMetadata(ValueBoxes.Double30Box));


public static bool GetIsColumnHeaderFontWeight(DependencyObject obj) => (bool)obj.GetValue(IsColumnHeaderFontWeightProperty);
public static void SetIsColumnHeaderFontWeight(DependencyObject obj, bool value) => obj.SetValue(IsColumnHeaderFontWeightProperty, ValueBoxes.BooleanBox(value));
/// <summary>
/// 表示<see cref="GridViewColumnHeader"/>是否采用粗体
/// </summary>
public static readonly DependencyProperty IsColumnHeaderFontWeightProperty =
DependencyProperty.RegisterAttached("IsColumnHeaderFontWeight", typeof(bool), typeof(ListViewAssistant), new PropertyMetadata(ValueBoxes.FalseBox));


public static Thickness GetListViewItemPadding(DependencyObject obj) => (Thickness)obj.GetValue(ListViewItemPaddingProperty);
public static void SetListViewItemPadding(DependencyObject obj, Thickness value) => obj.SetValue(ListViewItemPaddingProperty, value);
/// <summary>
/// 表示<see cref="ListViewItem"/>的内边距
/// </summary>
public static readonly DependencyProperty ListViewItemPaddingProperty =
DependencyProperty.RegisterAttached("ListViewItemPadding", typeof(Thickness), typeof(ListViewAssistant), new PropertyMetadata(default(Thickness)));
}
Expand Down
4 changes: 2 additions & 2 deletions CookPopularControl/Controls/Thumb/GridViewColumThumb.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Input;
using System.Windows;
using System.Windows.Input;



Expand All @@ -24,7 +25,6 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);

Mouse.OverrideCursor = null;
}
}
Expand Down
53 changes: 32 additions & 21 deletions CookPopularControl/CookPopularControl.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CookPopularControl/Themes/BaseStyle/ListBoxBaseStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
pc:ScrollBarAssistant.HorizontalScrollBarHeight="{TemplateBinding pc:ScrollBarAssistant.HorizontalScrollBarHeight}"
pc:ScrollBarAssistant.IsShowScrollBarRepeatButton="{TemplateBinding pc:ScrollBarAssistant.IsShowScrollBarRepeatButton}"
pc:ScrollBarAssistant.VerticalScrollBarWidth="{TemplateBinding pc:ScrollBarAssistant.VerticalScrollBarWidth}">
<!--<StackPanel SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" IsItemsHost="True" />-->
<!--<StackPanel x:Name="ItemsPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" IsItemsHost="True" />-->
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
Expand Down
Loading

0 comments on commit c0b454d

Please sign in to comment.