123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Windows.Data;
- namespace System.Windows.Forms
- {
- public class ColumnHeader
- {
- private static DataTemplate cellTemplate = (DataTemplate)System.Windows.Markup.XamlReader.Parse(
- "<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>" +
- "<StackPanel Orientation=\"Horizontal\" Margin=\"2,1,2,1\">" +
- "<Image Source=\"{Binding ImageSource}\" Width=\"{Binding ImageSourceWidth}\" Height=\"{Binding ImageSourceHeight}\" Margin=\"0,0,4,0\"/>" +
- "<TextBlock x:Name=\"PART_TextBlock\" Text=\"{Binding SubItems[0].Text}\" VerticalAlignment=\"Center\"/>" +
- "</StackPanel></DataTemplate>");
- private ListView owner;
- internal System.Windows.Controls.GridViewColumn column { get; }
- public string Text
- {
- get => column.Header?.ToString();
- set => column.Header = value;
- }
- public int Width
- {
- get => (int)(column.Width * (owner != null ? owner.DpiScale : 1));
- set => column.Width = value / (owner != null ? owner.DpiScale : 1);
- }
- internal void SetOwner(ListView owner) => this.owner = owner;
- internal void SetBinding(int columnIndex)
- {
- if (columnIndex == 0)
- column.CellTemplate = cellTemplate;
- else
- column.DisplayMemberBinding = new Binding($"SubItems[{columnIndex}].Text");
- }
- public ColumnHeader()
- {
- column = new();
- }
- }
- }
|