Change ExName to Attached Property

It is more powerfull and better then inherence and we can use colour emojies easier.
This commit is contained in:
Private 2024-06-18 15:48:29 +03:30
parent 1d4c5876c9
commit fcf1e9d23a
3 changed files with 662 additions and 650 deletions

View file

@ -1,9 +0,0 @@
using System.Windows.Controls;
namespace v2rayN.Base
{
internal class MyDGTextColumn : DataGridTextColumn
{
public string ExName { get; set; }
}
}

View file

@ -0,0 +1,20 @@
using System.Windows;
namespace v2rayN.Base
{
public static class MyDgTextColumnAttachedProperties
{
public static readonly DependencyProperty ExNameProperty =
DependencyProperty.RegisterAttached("ExName", typeof(string), typeof(MyDgTextColumnAttachedProperties), new PropertyMetadata(default(string)));
public static void SetExName(DependencyObject element, string value)
{
element.SetValue(ExNameProperty, value);
}
public static string GetExName(DependencyObject element)
{
return (string)element.GetValue(ExNameProperty);
}
}
}

View file

@ -313,7 +313,7 @@ namespace v2rayN.Views
return;
}
var colName = ((MyDGTextColumn)colHeader.Column).ExName;
var colName = MyDgTextColumnAttachedProperties.GetExName(colHeader.Column);
ViewModel?.SortServer(colName);
}
@ -484,9 +484,10 @@ namespace v2rayN.Views
var displayIndex = 0;
foreach (var item in lvColumnItem)
{
foreach (MyDGTextColumn item2 in lstProfiles.Columns)
foreach (var item2 in lstProfiles.Columns)
{
if (item2.ExName == item.Name)
var colName = MyDgTextColumnAttachedProperties.GetExName(item2);
if (colName == item.Name)
{
if (item.Width < 0)
{
@ -525,10 +526,10 @@ namespace v2rayN.Views
List<ColumnItem> lvColumnItem = new();
for (int k = 0; k < lstProfiles.Columns.Count; k++)
{
var item2 = (MyDGTextColumn)lstProfiles.Columns[k];
var item2 = lstProfiles.Columns[k];
lvColumnItem.Add(new()
{
Name = item2.ExName,
Name = MyDgTextColumnAttachedProperties.GetExName(item2),
Width = item2.Visibility == Visibility.Visible ? Utils.ToInt(item2.ActualWidth) : -1,
Index = item2.DisplayIndex
});