This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,332 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using DTS.Common.Controls;
using DTS.Common.Interface.RegionOfInterest.RegionOfInterestChannels;
using DTS.Common.Utils;
namespace RegionOfInterestChannels
{
public static class GridViewColumns
{
[AttachedPropertyBrowsableForType(typeof(GridView))]
public static object GetColumnsSource(DependencyObject obj)
{
return obj.GetValue(ColumnsSourceProperty);
}
public static void SetColumnsSource(DependencyObject obj, object value)
{
obj.SetValue(ColumnsSourceProperty, value);
}
// Using a DependencyProperty as the backing store for ColumnsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ColumnsSourceProperty =
DependencyProperty.RegisterAttached(
"ColumnsSource",
typeof(object),
typeof(GridViewColumns),
new UIPropertyMetadata(
null,
ColumnsSourceChanged));
[AttachedPropertyBrowsableForType(typeof(GridView))]
public static DataTemplateSelector GetCellDataTemplateSelector(DependencyObject obj)
{
return (DataTemplateSelector)obj.GetValue(CellDataTemplateSelectorProperty);
}
public static void SetCellDataTemplateSelector(DependencyObject obj, DataTemplateSelector value)
{
obj.SetValue(CellDataTemplateSelectorProperty, value);
}
public static readonly DependencyProperty CellDataTemplateSelectorProperty =
DependencyProperty.RegisterAttached(
"CellDataTemplateSelector",
typeof(DataTemplateSelector),
typeof(GridViewColumns),
new UIPropertyMetadata(null));
[AttachedPropertyBrowsableForType(typeof(GridView))]
public static DataTemplate GetCellDataTemplate(DependencyObject obj)
{
return (DataTemplate)obj.GetValue(CellDataTemplateProperty);
}
public static void SetCellDataTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(CellDataTemplateProperty, value);
}
public static readonly DependencyProperty CellDataTemplateProperty =
DependencyProperty.RegisterAttached(
"CellDataTemplate",
typeof(DataTemplate),
typeof(GridViewColumns),
new UIPropertyMetadata(null));
[AttachedPropertyBrowsableForType(typeof(GridView))]
public static string GetHeaderTextMember(DependencyObject obj)
{
return (string)obj.GetValue(HeaderTextMemberProperty);
}
public static void SetHeaderTextMember(DependencyObject obj, string value)
{
obj.SetValue(HeaderTextMemberProperty, value);
}
// Using a DependencyProperty as the backing store for HeaderTextMember. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeaderTextMemberProperty =
DependencyProperty.RegisterAttached("HeaderTextMember", typeof(string), typeof(GridViewColumns), new UIPropertyMetadata(null));
[AttachedPropertyBrowsableForType(typeof(GridView))]
public static string GetDisplayMember(DependencyObject obj)
{
return (string)obj.GetValue(DisplayMemberProperty);
}
public static void SetDisplayMember(DependencyObject obj, string value)
{
obj.SetValue(DisplayMemberProperty, value);
}
// Using a DependencyProperty as the backing store for DisplayMember. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DisplayMemberProperty =
DependencyProperty.RegisterAttached("DisplayMember", typeof(string), typeof(GridViewColumns), new UIPropertyMetadata(null));
private static void ColumnsSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
GridView gridView = obj as GridView;
if (gridView != null)
{
gridView.Columns.Clear();
if (e.OldValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(e.OldValue);
if (view != null)
RemoveHandlers(gridView, view);
}
if (e.NewValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(e.NewValue);
if (view != null)
{
AddHandlers(gridView, view);
CreateColumns(gridView, view);
}
}
}
}
private static IDictionary<ICollectionView, List<GridView>> _gridViewsByColumnsSource =
new Dictionary<ICollectionView, List<GridView>>();
private static List<GridView> GetGridViewsForColumnSource(ICollectionView columnSource)
{
List<GridView> gridViews;
if (!_gridViewsByColumnsSource.TryGetValue(columnSource, out gridViews))
{
gridViews = new List<GridView>();
_gridViewsByColumnsSource.Add(columnSource, gridViews);
}
return gridViews;
}
private static void AddHandlers(GridView gridView, ICollectionView view)
{
GetGridViewsForColumnSource(view).Add(gridView);
view.CollectionChanged += ColumnsSource_CollectionChanged;
}
private static void CreateColumns(GridView gridView, ICollectionView view)
{
foreach (var item in view)
{
GridViewColumn column = CreateColumn(gridView, item);
gridView.Columns.Add(column);
}
}
private static void RemoveHandlers(GridView gridView, ICollectionView view)
{
view.CollectionChanged -= ColumnsSource_CollectionChanged;
GetGridViewsForColumnSource(view).Remove(gridView);
}
private static void ColumnsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
ICollectionView view = sender as ICollectionView;
var gridViews = GetGridViewsForColumnSource(view);
if (gridViews == null || gridViews.Count == 0)
return;
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (var gridView in gridViews)
{
for (int i = 0; i < e.NewItems.Count; i++)
{
GridViewColumn column = CreateColumn(gridView, e.NewItems[i]);
gridView.Columns.Insert(e.NewStartingIndex + i, column);
}
}
break;
case NotifyCollectionChangedAction.Move:
foreach (var gridView in gridViews)
{
List<GridViewColumn> columns = new List<GridViewColumn>();
for (int i = 0; i < e.OldItems.Count; i++)
{
GridViewColumn column = gridView.Columns[e.OldStartingIndex + i];
columns.Add(column);
}
for (int i = 0; i < e.NewItems.Count; i++)
{
GridViewColumn column = columns[i];
gridView.Columns.Insert(e.NewStartingIndex + i, column);
}
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (var gridView in gridViews)
{
for (int i = 0; i < e.OldItems.Count; i++)
{
gridView.Columns.RemoveAt(e.OldStartingIndex);
}
}
break;
case NotifyCollectionChangedAction.Replace:
foreach (var gridView in gridViews)
{
for (int i = 0; i < e.NewItems.Count; i++)
{
GridViewColumn column = CreateColumn(gridView, e.NewItems[i]);
gridView.Columns[e.NewStartingIndex + i] = column;
}
}
break;
case NotifyCollectionChangedAction.Reset:
foreach (var gridView in gridViews)
{
gridView.Columns.Clear();
CreateColumns(gridView, sender as ICollectionView);
}
break;
default:
break;
}
}
private static void GridViewColumnHeaderSearchable_OnSearch(object sender, RoutedEventArgs e)
{
var searchTerm = (string)e.OriginalSource;
var columnTag = (sender as GridViewColumnHeaderSearchable)?.Tag;
var viewModel = (IRegionOfInterestChannelsViewModel)(sender as GridViewColumnHeaderSearchable)?.DataContext;
viewModel?.Filter(columnTag, searchTerm);
}
private static void GridViewColumnHeader_OnClick(object sender, RoutedEventArgs e)
{
var columnTag = (sender as GridViewColumnHeaderSearchable)?.Tag ?? Utils.FindChild<GridViewColumnHeaderSearchable>((DependencyObject)e.OriginalSource, null)?.Tag;
var viewModel = (IRegionOfInterestChannelsViewModel)(sender as GridViewColumnHeaderSearchable)?.DataContext;
viewModel?.Sort(columnTag, true);
}
private static void GridViewColumnHeaderSelectable_OnSelectAll(object sender, RoutedEventArgs e)
{
var columnTag = (sender as GridViewColumnHeaderSelectable)?.Tag.ToString();
var columnIndex = GetArrayIndex(columnTag);
var viewModel = (IRegionOfInterestChannelsViewModel)(sender as GridViewColumnHeaderSelectable)?.DataContext;
viewModel?.SelectAll(columnIndex, (bool)(e?.OriginalSource ?? false));
}
private static GridViewColumn CreateColumn(GridView gridView, object columnSource)
{
GridViewColumn column = new GridViewColumn();
string headerTextMember = GetHeaderTextMember(gridView);
string displayMember = GetDisplayMember(gridView);
DataTemplate template = GetCellDataTemplate(gridView);
DataTemplateSelector selector = GetCellDataTemplateSelector(gridView);
if (!string.IsNullOrEmpty(headerTextMember))
{
var columnSourceType = (System.Type)GetPropertyValue(columnSource, "MemberType");
switch (true)
{
case bool _ when columnSourceType == typeof(bool):
column.Header = new GridViewColumnHeaderSelectable
{
HeaderTitle = (string)GetPropertyValue(columnSource, headerTextMember),
Tag = (string)GetPropertyValue(columnSource, displayMember),
};
((GridViewColumnHeaderSelectable)column.Header).SelectAll += GridViewColumnHeaderSelectable_OnSelectAll;
break;
case bool _ when columnSourceType == typeof(string):
column.Header = new GridViewColumnHeaderSearchable
{
HeaderTitle = (string)GetPropertyValue(columnSource, headerTextMember),
Tag = (string)GetPropertyValue(columnSource, displayMember),
};
((GridViewColumnHeaderSearchable)column.Header).Search += GridViewColumnHeaderSearchable_OnSearch;
((GridViewColumnHeaderSearchable)column.Header).ClickHandler += GridViewColumnHeader_OnClick;
break;
default:
column.Header = (string)GetPropertyValue(columnSource, headerTextMember);
break;
}
//column.Header = GetPropertyValue(columnSource, headerTextMember);
}
//remember, remember: selector < template < displaymember
if (null != selector)
{
column.CellTemplateSelector = selector;
}
if (null != template)
{
column.CellTemplate = template;
}
if (!string.IsNullOrEmpty(displayMember))
{
//string propertyName = GetPropertyValue(columnSource, displayMember) as string;
//column.DisplayMemberBinding = new Binding(propertyName);
}
return column;
}
private static object GetPropertyValue(object obj, string propertyName)
{
if (obj != null)
{
PropertyInfo prop = obj.GetType().GetProperty(propertyName);
if (prop != null)
return prop.GetValue(obj, null);
}
return null;
}
private static int GetArrayIndex(string fromString)
{
var openBracket = fromString.LastIndexOf("[");
var closeBracket = fromString.LastIndexOf("]");
var numString = fromString.Substring(openBracket + 1, closeBracket - openBracket - 1);
if (int.TryParse(numString, out var index))
{
return index;
}
return -1;
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace RegionOfInterestChannels
{
public class RegionOfInterestChannelsDataTemplateSelector : DataTemplateSelector
{
public DataTemplate TextBlockDataTemplate { get; set; }
public DataTemplate CheckBoxDataTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is ChannelEnabler)
{
GridViewRowPresenter presenter = (container as ContentPresenter).Parent as GridViewRowPresenter;
if (presenter != null)
{
int checkStartColumn = -1;
for (int i = 0; i < presenter.Columns.Count; i++)
{
ContentPresenter templated = VisualTreeHelper.GetChild(presenter, i) as ContentPresenter;
var columnPropertyType = item.GetType().GetProperty(presenter.Columns[i].Header.ToString().Replace(" ", ""))?.GetValue(item, null).GetType();
if (null == columnPropertyType && checkStartColumn < 0)
{
checkStartColumn = i;
}
if (templated != null && templated.Equals(container as ContentPresenter))
{
switch (Type.GetTypeCode(columnPropertyType))
{
case TypeCode.String:
(container as ContentPresenter).Tag = item.GetType().GetProperty(presenter.Columns[i].Header.ToString().Replace(" ", ""))?.GetValue(item, null);
return TextBlockDataTemplate;
case TypeCode.Boolean:
default:
(container as ContentPresenter).Tag = i - checkStartColumn;
return CheckBoxDataTemplate;
}
}
}
}
return CheckBoxDataTemplate;
}
return TextBlockDataTemplate;
}
}
}

View File

@@ -0,0 +1,83 @@
<base:BaseView x:Class="RegionOfInterestChannels.RegionOfInterestChannelsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:behaviors="clr-namespace:DTS.Common.Behaviors;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:strings="clr-namespace:RegionOfInterestChannels"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RegionOfInterestChannels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}">
<Setter Property="FontFamily" Value="Courier New"/>
</Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<local:StateListIndexConverter x:Key="StateListIndexConverter" />
<local:RegionOfInterestChannelsDataTemplateSelector x:Key="DataTemplateSelector">
<local:RegionOfInterestChannelsDataTemplateSelector.CheckBoxDataTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" IsChecked="{Binding Path=Checked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="ROIChannelCheckBox">
<CheckBox.DataContext>
<MultiBinding Converter="{StaticResource StateListIndexConverter}">
<Binding Path="ROIIncludes"/>
<Binding Path="Tag" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}" />
</MultiBinding>
</CheckBox.DataContext>
</CheckBox>
</DataTemplate>
</local:RegionOfInterestChannelsDataTemplateSelector.CheckBoxDataTemplate>
<local:RegionOfInterestChannelsDataTemplateSelector.TextBlockDataTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Left" AutomationProperties.AutomationId="ROIChannelTextLbl"
Text="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}, FallbackValue='???????????????A'}"
Loaded="TextBlock_Loaded" FontFamily="Courier New"/>
</DataTemplate>
</local:RegionOfInterestChannelsDataTemplateSelector.TextBlockDataTemplate>
</local:RegionOfInterestChannelsDataTemplateSelector>
</ResourceDictionary>
</base:BaseView.Resources>
<Grid Background="{StaticResource Brush_ApplicationContentBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Style="{StaticResource SimpleHeader}" Grid.Row="0"
Content="{local:TranslateExtension Title}"
HorizontalAlignment="Stretch"
VerticalAlignment="Top" AutomationProperties.AutomationId="ROIChannelsTitleLabel" />
<ListView Grid.Row="1" ItemsSource="{Binding ChannelList, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="ROIChannelsListView" GridViewColumnHeader.Click="GridViewColumnHeader_OnClick"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource TTS_ListViewItemStyle}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="FontFamily" Value="Courier New" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<controls:AutoSizedGridView local:GridViewColumns.HeaderTextMember="HeaderText"
local:GridViewColumns.DisplayMember="DisplayMember"
local:GridViewColumns.ColumnsSource="{Binding Columns}"
local:GridViewColumns.CellDataTemplateSelector="{StaticResource DataTemplateSelector}"/>
</ListView.View>
</ListView>
</Grid>
</Grid>
</base:BaseView>

View File

@@ -0,0 +1,48 @@
using DTS.Common.Controls;
using DTS.Common.Interface.RegionOfInterest.RegionOfInterestChannels;
using DTS.Common.Utils;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace RegionOfInterestChannels
{
/// <summary>
/// Interaction logic for RegionOfInterestChannelsView.xaml
/// </summary>
public partial class RegionOfInterestChannelsView : IRegionOfInterestChannelsView
{
public RegionOfInterestChannelsView()
{
InitializeComponent();
}
private void GridViewColumnHeader_OnClick(object sender, RoutedEventArgs e)
{
var vm = (IRegionOfInterestChannelsViewModel)DataContext;
var columnTag = (sender as GridViewColumnHeaderSearchable)?.Tag ?? Utils.FindChild<GridViewColumnHeaderSearchable>((DependencyObject)e.OriginalSource, null)?.Tag ??
(sender as GridViewColumnHeaderSelectable)?.Tag ?? Utils.FindChild<GridViewColumnHeaderSelectable>((DependencyObject)e.OriginalSource, null)?.Tag;
vm?.Sort(columnTag, true);
}
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
{
if (!(sender is TextBlock tb)) return;
if (!((tb.TemplatedParent as ContentPresenter)?.Parent is GridViewRowPresenter presenter)) return;
for (int i = 0; i < presenter.Columns.Count; i++)
{
if (!(VisualTreeHelper.GetChild(presenter, i) is ContentPresenter templated) ||
!templated.Equals((ContentPresenter)tb.TemplatedParent)) continue;
//found our column
if (presenter.Columns[i].ActualWidth < tb.ActualWidth && double.IsNaN(presenter.Columns[i].Width))
{
//now that bindings/templates are applied, control width > column width
//force remeasure
presenter.Columns[i].Width = tb.ActualWidth;
presenter.Columns[i].Width = double.NaN;
}
break;
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
namespace RegionOfInterestChannels
{
public class StateListIndexConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (null == values || values.Length != 2)
return null;
if (!(values[1] is int idx) || !(values[0] is IEnumerable<State> states) || states.Count() <= idx)
return null;
return states.ElementAt(idx);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}