【发布时间】:2019-04-17 09:54:44
【问题描述】:
UWP 社区工具包 DataGrid 在列标题中为排序图标保留了一点空间,这让事情看起来很奇怪。当您不使用排序时(甚至当列不可排序时),数据网格列标题中有一个 35 像素宽的空间,该空间没有任何内容。如果您将列宽变小,它会在您真正需要之前很久就切断您的标题文本。
我制定了一个解决方案,方法是在加载标题后获取标题,向下浏览可视化树,并手动分配我需要的属性 - 但它似乎需要做很多工作,并且如果模板发生更改就会中断。 ????
有没有更好的方法来做到这一点?
我现在如何修改标题:
var mainPanel = (Windows.UI.Xaml.Controls.Grid)VisualTreeHelper.GetChild(header, 0);
if (mainPanel != null)
{
var contentPanel = (Windows.UI.Xaml.Controls.Grid)VisualTreeHelper.GetChild(mainPanel, 1);
contentPanel.ColumnDefinitions[1].MinWidth = 0;
var fontIcon = (FontIcon)VisualTreeHelper.GetChild(contentPanel, 1);
fontIcon.Margin = new Thickness(2, 0, 2, 0);
fontIcon.SetBinding(UIElement.VisibilityProperty,//hide it instead of using opacity
new Binding()
{
Source = fontIcon,
Path = new PropertyPath(nameof(FontIcon.Opacity)),
Converter = new ShowSortingIconValueConverter()
});
SetCustomizeHeader(header, false);
}
【问题讨论】:
标签: uwp datagrid windows-community-toolkit