-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from dojo90/11-implement-custom-message-resolver
11 implement custom message resolver
- Loading branch information
Showing
24 changed files
with
1,501 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Reactive.Linq; | ||
using System.Windows.Controls; | ||
using NLog; | ||
|
||
namespace DJ.Helper | ||
{ | ||
/// <summary> | ||
/// Represents a view mode that displays data items in columns for a System.Windows.Controls.ListView control with auto sized columns based on the column content | ||
/// Used to fix the column width: https://stackoverflow.com/questions/60147905/column-width-adjustment-is-broken-if-using-multibinding-on-displaymemberbinding | ||
/// </summary> | ||
public class AutoSizedGridView : GridView | ||
{ | ||
private int _MaxLoggerNameLength; | ||
|
||
protected override void PrepareItem(ListViewItem item) | ||
{ | ||
if (item.DataContext is LogEventInfo info) | ||
{ | ||
if (info.LoggerName.Length > _MaxLoggerNameLength) | ||
{ | ||
_MaxLoggerNameLength = info.LoggerName.Length; | ||
Observable.Timer(TimeSpan.FromMilliseconds(1)).ObserveOnDispatcher().Subscribe(l => | ||
{ | ||
foreach (GridViewColumn column in Columns) | ||
{ | ||
//setting NaN for the column width automatically determines the required width enough to hold the content completely. | ||
//if column width was set to NaN already, set it ActualWidth temporarily and set to NaN. This raises the property change event and re computes the width. | ||
if (double.IsNaN(column.Width)) | ||
{ | ||
column.Width = column.ActualWidth; | ||
column.Width = double.NaN; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
base.PrepareItem(item); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/NLogViewer/Helper/ListViewLayoutManager/ConverterGridViewColumn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
|
||
namespace DJ.Helper.ListViewLayoutManager | ||
{ | ||
public abstract class ConverterGridViewColumn : GridViewColumn, IValueConverter | ||
{ | ||
public Type BindingType => _BindingType; | ||
private readonly Type _BindingType; | ||
|
||
// ############################################################################################################################## | ||
// Constructor | ||
// ############################################################################################################################## | ||
|
||
#region Constructor | ||
|
||
protected ConverterGridViewColumn(Type bindingType) | ||
{ | ||
if (bindingType == null) | ||
{ | ||
throw new ArgumentNullException(nameof(bindingType)); | ||
} | ||
|
||
this._BindingType = bindingType; | ||
|
||
Binding binding = new Binding {Mode = BindingMode.OneWay, Converter = this}; | ||
DisplayMemberBinding = binding; | ||
} | ||
|
||
#endregion | ||
|
||
// ############################################################################################################################## | ||
// IValueConverter | ||
// ############################################################################################################################## | ||
|
||
#region IValueConverter | ||
|
||
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (!_BindingType.IsInstanceOfType(value)) | ||
{ | ||
throw new InvalidOperationException(); | ||
} | ||
|
||
return ConvertValue(value); | ||
} | ||
|
||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected abstract object ConvertValue(object value); | ||
|
||
#endregion | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/NLogViewer/Helper/ListViewLayoutManager/FixedColumn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace DJ.Helper.ListViewLayoutManager | ||
{ | ||
public sealed class FixedColumn : LayoutColumn | ||
{ | ||
public static bool IsFixedColumn(GridViewColumn column) | ||
{ | ||
if (column == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return HasPropertyValue(column, WidthProperty); | ||
} | ||
|
||
public static double? GetFixedWidth(GridViewColumn column) | ||
{ | ||
return GetColumnWidth(column, WidthProperty); | ||
} | ||
|
||
public static GridViewColumn ApplyWidth(GridViewColumn gridViewColumn, double width) | ||
{ | ||
SetWidth(gridViewColumn, width); | ||
return gridViewColumn; | ||
} | ||
|
||
// ############################################################################################################################## | ||
// AttachedProperties | ||
// ############################################################################################################################## | ||
|
||
#region AttachedProperties | ||
|
||
public static double GetWidth(DependencyObject obj) | ||
{ | ||
return (double) obj.GetValue(WidthProperty); | ||
} | ||
|
||
public static void SetWidth(DependencyObject obj, double width) | ||
{ | ||
obj.SetValue(WidthProperty, width); | ||
} | ||
|
||
public static readonly DependencyProperty WidthProperty = DependencyProperty.RegisterAttached("Width", typeof(double), typeof(FixedColumn)); | ||
|
||
#endregion | ||
|
||
// ############################################################################################################################## | ||
// Constructor | ||
// ############################################################################################################################## | ||
|
||
#region Constructor | ||
|
||
private FixedColumn() | ||
{ | ||
} | ||
|
||
#endregion | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/NLogViewer/Helper/ListViewLayoutManager/ImageGridViewColumn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace DJ.Helper.ListViewLayoutManager | ||
{ | ||
public abstract class ImageGridViewColumn : GridViewColumn, IValueConverter | ||
{ | ||
// ############################################################################################################################## | ||
// Constructor | ||
// ############################################################################################################################## | ||
|
||
#region Constructor | ||
|
||
protected ImageGridViewColumn(Stretch imageStretch) | ||
{ | ||
FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image)); | ||
|
||
Binding imageSourceBinding = new Binding {Converter = this, Mode = BindingMode.OneWay}; | ||
imageElement.SetBinding(Image.SourceProperty, imageSourceBinding); | ||
|
||
Binding imageStretchBinding = new Binding {Source = imageStretch}; | ||
imageElement.SetBinding(Image.StretchProperty, imageStretchBinding); | ||
|
||
DataTemplate template = new DataTemplate {VisualTree = imageElement}; | ||
CellTemplate = template; | ||
} | ||
|
||
protected ImageGridViewColumn() : this(Stretch.None) | ||
{ | ||
} | ||
|
||
#endregion | ||
|
||
// ############################################################################################################################## | ||
// IValueConverter | ||
// ############################################################################################################################## | ||
|
||
#region IValueConverter | ||
|
||
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return GetImageSource(value); | ||
} | ||
|
||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected abstract ImageSource GetImageSource(object value); | ||
|
||
#endregion | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/NLogViewer/Helper/ListViewLayoutManager/LayoutColumn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace DJ.Helper.ListViewLayoutManager | ||
{ | ||
public abstract class LayoutColumn | ||
{ | ||
protected static bool HasPropertyValue(GridViewColumn column, DependencyProperty dp) | ||
{ | ||
if (column == null) | ||
{ | ||
throw new ArgumentNullException(nameof(column)); | ||
} | ||
|
||
object value = column.ReadLocalValue(dp); | ||
if (value?.GetType() == dp.PropertyType) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected static double? GetColumnWidth(GridViewColumn column, DependencyProperty dp) | ||
{ | ||
if (column == null) | ||
{ | ||
throw new ArgumentNullException(nameof(column)); | ||
} | ||
|
||
object value = column.ReadLocalValue(dp); | ||
if (value?.GetType() == dp.PropertyType) | ||
{ | ||
return (double) value; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.