added MultiFormatDataView in first state,

fixed some warnings
master
Jonas Arnold 3 years ago
parent 429c7e842d
commit c11c99b3c8
  1. 83
      MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs
  2. 133
      MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.xaml
  3. 10
      MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs
  4. 4
      MultiTerm.Wpf.CustomControl/MultiTerm.Wpf.CustomControl.csproj
  5. 1
      MultiTerm.Wpf.CustomControl/Themes/Generic.xaml

@ -0,0 +1,83 @@
using MultiTerm.Protocols.Model;
using System;
using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
namespace MultiTerm.Wpf.CustomControl;
/// <summary>
/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
///
/// Step 1a) Using this custom control in a XAML file that exists in the current project.
/// Add this XmlNamespace attribute to the root element of the markup file where it is
/// to be used:
///
/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.CustomControl.MultiFormatDataView"
///
///
/// Step 1b) Using this custom control in a XAML file that exists in a different project.
/// Add this XmlNamespace attribute to the root element of the markup file where it is
/// to be used:
///
/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.CustomControl.MultiFormatDataView;assembly=MultiTerm.Wpf.CustomControl.MultiFormatDataView"
///
/// You will also need to add a project reference from the project where the XAML file lives
/// to this project and Rebuild to avoid compilation errors:
///
/// Right click on the target project in the Solution Explorer and
/// "Add Reference"->"Projects"->[Browse to and select this project]
///
///
/// Step 2)
/// Go ahead and use your control in the XAML file.
///
/// <MyNamespace:MultiFormatDataView/>
///
/// </summary>
public class MultiFormatDataView : Control
{
#region Dependency Properties
public static readonly DependencyProperty DataSourceProperty =
DependencyProperty.Register("DataSource",
typeof(IEnumerable), typeof(MultiFormatDataView),
new PropertyMetadata(null, OnDataSourcePropertyChanged));
/// <summary>
/// .NET Property for DataSource.
/// </summary>
[Bindable(true)]
public IEnumerable DataSource
{
get { return (IEnumerable)GetValue(DataSourceProperty); }
set { SetValue(DataSourceProperty, value); }
}
#endregion
static MultiFormatDataView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MultiFormatDataView), new FrameworkPropertyMetadata(typeof(MultiFormatDataView)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
private static void OnDataSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// extract instance and guard null
if (d is not MultiFormatDataView mfdv) { return; }
// extract instance of new Value and guard null
if (e.NewValue is not IEnumerable enumerable) { return; }
// check if enumerable items are all of correct type
foreach (var item in enumerable)
{
if (item is not DataLine)
{ throw new ArgumentException($"{nameof(DataSourceProperty)} must be of type {nameof(DataLine)}"); }
}
}
}

@ -0,0 +1,133 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MultiTerm.Wpf.CustomControl"
xmlns:wpftk="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel">
<Style TargetType="{x:Type local:MultiFormatDataView}">
<Style.Resources>
<SolidColorBrush x:Key="CHAR_Background" Color="#B4EBEB"/>
<SolidColorBrush x:Key="HEX_Background" Color="#C8C8FF"/>
<SolidColorBrush x:Key="BIN_Background" Color="#C8FFC8"/>
<DataTemplate x:Key="dataContainerTemplate">
<StackPanel Orientation="Vertical" Margin="0 0 5 0">
<!-- Character -->
<Border BorderThickness="0">
<Label Content="{Binding DisplayStringUtf16}">
<Label.Style>
<Style TargetType="Label">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cbHex,Path=IsChecked}" Value="True">
<Setter Property="HorizontalAlignment" Value="Right"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cbBin,Path=IsChecked}" Value="True">
<Setter Property="HorizontalAlignment" Value="Right"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cbCharacter,Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cbHex,Path=IsChecked}" Value="True">
<Setter Property="Background" Value="{StaticResource CHAR_Background}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cbBin,Path=IsChecked}" Value="True">
<Setter Property="Background" Value="{StaticResource CHAR_Background}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<!-- Hexadecimal -->
<Border BorderThickness="0" Background="{StaticResource HEX_Background}">
<Label Content="{Binding DisplayStringHex}" HorizontalAlignment="Right"/>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cbHex,Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<!-- Binary -->
<Border BorderThickness="0" Background="{StaticResource BIN_Background}">
<Label Content="{Binding DisplayStringBin}" HorizontalAlignment="Right"/>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cbBin,Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</StackPanel>
</DataTemplate>
</Style.Resources>
<!-- Template -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MultiFormatDataView}">
<DockPanel>
<GroupBox Header="Display Formats" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal" >
<CheckBox Content="Character" x:Name="cbCharacter" Padding="20 0" IsChecked="True"/>
<CheckBox Content="Hexadecimal" x:Name="cbHex" Padding="20 0"/>
<CheckBox Content="Binary" x:Name="cbBin" Padding="20 0"/>
</StackPanel>
</GroupBox>
<ItemsControl ItemsSource="{TemplateBinding DataSource}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="true"
ScrollViewer.PanningMode="VerticalOnly"
HorizontalAlignment="Left">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Characters}" HorizontalAlignment="Left"
ItemTemplate="{StaticResource dataContainerTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<wpftk:VirtualizingWrapPanel Orientation="Vertical"
VirtualizingPanel.CacheLengthUnit="Item"
VirtualizingPanel.ScrollUnit="Item">
</wpftk:VirtualizingWrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

@ -71,8 +71,7 @@ public class MultiFormatTextBox : Control
private ComboBox? comboBox; private ComboBox? comboBox;
private RichTextBox? richTextBox; private RichTextBox? richTextBox;
private Format? currentlySelectedFormat; private Format? currentlySelectedFormat;
private int offsetContentStartToFormatStart; private readonly object lockObj = new();
private object lockObj = new();
#endregion #endregion
@ -128,7 +127,6 @@ public class MultiFormatTextBox : Control
this.richTextBox.AcceptsReturn = false; this.richTextBox.AcceptsReturn = false;
this.richTextBox.KeyDown += RichTextBox_KeyDown; this.richTextBox.KeyDown += RichTextBox_KeyDown;
this.richTextBox.TextChanged += RichTextBox_TextChanged; this.richTextBox.TextChanged += RichTextBox_TextChanged;
this.offsetContentStartToFormatStart = 0;
} }
else else
{ {
@ -139,7 +137,7 @@ public class MultiFormatTextBox : Control
private static void OnCurrentMultiFormatStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) private static void OnCurrentMultiFormatStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
// extract instance and guard null // extract instance and guard null
if (d is not MultiFormatTextBox mftb) { return; } // if (d is not MultiFormatTextBox mftb) { return; }
// nothing to do // nothing to do
} }
@ -244,7 +242,7 @@ public class MultiFormatTextBox : Control
} }
// update CurrentMultiFormatString // update CurrentMultiFormatString
this.CurrentMultiFormatString = this.ConvertRtbContentToMultiFormatString(this.richTextBox!); this.CurrentMultiFormatString = ConvertRtbContentToMultiFormatString(this.richTextBox!);
} }
} }
@ -264,7 +262,7 @@ public class MultiFormatTextBox : Control
rtb.Selection.Select(end, end); rtb.Selection.Select(end, end);
} }
private MultiFormatString ConvertRtbContentToMultiFormatString(RichTextBox rtb) private static MultiFormatString ConvertRtbContentToMultiFormatString(RichTextBox rtb)
{ {
MultiFormatString multiFormatString = new(); MultiFormatString multiFormatString = new();
// store current caret position // store current caret position

@ -6,6 +6,10 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="VirtualizingWrapPanel" Version="1.5.7" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MultiTerm.Core\MultiTerm.Core.csproj" /> <ProjectReference Include="..\MultiTerm.Core\MultiTerm.Core.csproj" />
</ItemGroup> </ItemGroup>

@ -7,6 +7,7 @@
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MultiTerm.Wpf.CustomControl;component/ExtendedTabControl/ExtendedTabControl.xaml"/> <ResourceDictionary Source="/MultiTerm.Wpf.CustomControl;component/ExtendedTabControl/ExtendedTabControl.xaml"/>
<ResourceDictionary Source="/MultiTerm.Wpf.CustomControl;component/MultiFormatTextBox/MultiFormatTextBox.xaml"/> <ResourceDictionary Source="/MultiTerm.Wpf.CustomControl;component/MultiFormatTextBox/MultiFormatTextBox.xaml"/>
<ResourceDictionary Source="/MultiTerm.Wpf.CustomControl;component/MultiFormatDataView/MultiFormatDataView.xaml"/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>

Loading…
Cancel
Save