diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
index aa03330cc5..7384daae30 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
@@ -1,13 +1,17 @@
+using System;
+using Avalonia.Data;
+using Avalonia.Media;
+
namespace Avalonia.Diagnostics.ViewModels
{
internal class AvaloniaPropertyViewModel : PropertyViewModel
{
private readonly AvaloniaObject _target;
- private System.Type _assignedType;
+ private Type _assignedType;
private object? _value;
private string _priority;
private string _group;
- private readonly System.Type _propertyType;
+ private readonly Type _propertyType;
#nullable disable
// Remove "nullable disable" after MemberNotNull will work on our CI.
@@ -28,13 +32,9 @@ namespace Avalonia.Diagnostics.ViewModels
public AvaloniaProperty Property { get; }
public override object Key => Property;
public override string Name { get; }
- public override bool? IsAttached =>
- Property.IsAttached;
-
- public override string Priority =>
- _priority;
-
- public override System.Type AssignedType => _assignedType;
+ public override bool? IsAttached => Property.IsAttached;
+ public override string Priority => _priority;
+ public override Type AssignedType => _assignedType;
public override string? Value
{
@@ -53,30 +53,58 @@ namespace Avalonia.Diagnostics.ViewModels
public override string Group => _group;
- public override System.Type? DeclaringType { get; }
- public override System.Type PropertyType => _propertyType;
+ public override Type? DeclaringType { get; }
+ public override Type PropertyType => _propertyType;
// [MemberNotNull(nameof(_type), nameof(_group), nameof(_priority))]
public override void Update()
{
if (Property.IsDirect)
{
- RaiseAndSetIfChanged(ref _value, _target.GetValue(Property), nameof(Value));
- RaiseAndSetIfChanged(ref _assignedType,_value?.GetType() ?? Property.PropertyType, nameof(AssignedType));
+ object? value;
+ Type? valueType = null;
+
+ try
+ {
+ value = _target.GetValue(Property);
+ valueType = value?.GetType();
+ }
+ catch (Exception e)
+ {
+ value = e.GetBaseException();
+ }
+
+ RaiseAndSetIfChanged(ref _value, value, nameof(Value));
+ RaiseAndSetIfChanged(ref _assignedType, valueType ?? Property.PropertyType, nameof(AssignedType));
RaiseAndSetIfChanged(ref _priority, "Direct", nameof(Priority));
_group = "Properties";
}
else
{
- var val = _target.GetDiagnostic(Property);
+ object? value;
+ Type? valueType = null;
+ BindingPriority? priority = null;
+
+ try
+ {
+ var diag = _target.GetDiagnostic(Property);
+
+ value = diag.Value;
+ valueType = value?.GetType();
+ priority = diag.Priority;
+ }
+ catch (Exception e)
+ {
+ value = e.GetBaseException();
+ }
- RaiseAndSetIfChanged(ref _value, val?.Value, nameof(Value));
- RaiseAndSetIfChanged(ref _assignedType, _value?.GetType() ?? Property.PropertyType, nameof(AssignedType));
+ RaiseAndSetIfChanged(ref _value, value, nameof(Value));
+ RaiseAndSetIfChanged(ref _assignedType, valueType ?? Property.PropertyType, nameof(AssignedType));
- if (val != null)
+ if (priority != null)
{
- RaiseAndSetIfChanged(ref _priority, val.Priority.ToString(), nameof(Priority));
+ RaiseAndSetIfChanged(ref _priority, priority.ToString()!, nameof(Priority));
RaiseAndSetIfChanged(ref _group, IsAttached == true ? "Attached Properties" : "Properties", nameof(Group));
}
else
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
index e2d8a30c8a..73fb615b32 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
@@ -1,13 +1,15 @@
-using System.Reflection;
+using System;
+using System.Reflection;
+using Avalonia.Media;
namespace Avalonia.Diagnostics.ViewModels
{
internal class ClrPropertyViewModel : PropertyViewModel
{
private readonly object _target;
- private System.Type _assignedType;
+ private Type _assignedType;
private object? _value;
- private readonly System.Type _propertyType;
+ private readonly Type _propertyType;
#nullable disable
// Remove "nullable disable" after MemberNotNull will work on our CI.
@@ -25,6 +27,7 @@ namespace Avalonia.Diagnostics.ViewModels
{
Name = property.DeclaringType.Name + '.' + property.Name;
}
+
DeclaringType = property.DeclaringType;
_propertyType = property.PropertyType;
@@ -36,10 +39,10 @@ namespace Avalonia.Diagnostics.ViewModels
public override string Name { get; }
public override string Group => "CLR Properties";
- public override System.Type AssignedType => _assignedType;
- public override System.Type PropertyType => _propertyType;
+ public override Type AssignedType => _assignedType;
+ public override Type PropertyType => _propertyType;
- public override string? Value
+ public override string? Value
{
get => ConvertToString(_value);
set
@@ -54,20 +57,30 @@ namespace Avalonia.Diagnostics.ViewModels
}
}
- public override string Priority =>
- string.Empty;
+ public override string Priority => string.Empty;
- public override bool? IsAttached =>
- default;
+ public override bool? IsAttached => default;
- public override System.Type? DeclaringType { get; }
+ public override Type? DeclaringType { get; }
// [MemberNotNull(nameof(_type))]
public override void Update()
{
- var val = Property.GetValue(_target);
- RaiseAndSetIfChanged(ref _value, val, nameof(Value));
- RaiseAndSetIfChanged(ref _assignedType, _value?.GetType() ?? Property.PropertyType, nameof(AssignedType));
+ object? value;
+ Type? valueType = null;
+
+ try
+ {
+ value = Property.GetValue(_target);
+ valueType = value?.GetType();
+ }
+ catch (Exception e)
+ {
+ value = e.GetBaseException();
+ }
+
+ RaiseAndSetIfChanged(ref _value, value, nameof(Value));
+ RaiseAndSetIfChanged(ref _assignedType, valueType ?? Property.PropertyType, nameof(AssignedType));
RaisePropertyChanged(nameof(Type));
}
}
diff --git a/src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml b/src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml
index c5d7ad55d7..81bd8f39c5 100644
--- a/src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml
+++ b/src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml
@@ -4,6 +4,7 @@
Selector="NativeMenuBar">
+
@@ -18,6 +19,8 @@
+
+
diff --git a/src/Avalonia.Themes.Default/IBitmapToImageConverter.cs b/src/Avalonia.Themes.Default/IBitmapToImageConverter.cs
new file mode 100644
index 0000000000..9b7fcecf45
--- /dev/null
+++ b/src/Avalonia.Themes.Default/IBitmapToImageConverter.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Data.Converters;
+using Avalonia.Media.Imaging;
+
+namespace Avalonia.Themes.Default
+{
+ internal class IBitmapToImageConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value != null && value is IBitmap bm)
+ return new Image { Source=bm };
+
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml b/src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml
index 7860e08ef5..d40ba0cc1d 100644
--- a/src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml
+++ b/src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml
@@ -4,12 +4,13 @@
x:CompileBindings="True"
Selector="NativeMenuBar">
-
+
+
diff --git a/src/Avalonia.Themes.Fluent/IBitmapToImageConverter.cs b/src/Avalonia.Themes.Fluent/IBitmapToImageConverter.cs
new file mode 100644
index 0000000000..34670882f8
--- /dev/null
+++ b/src/Avalonia.Themes.Fluent/IBitmapToImageConverter.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Data.Converters;
+using Avalonia.Media.Imaging;
+
+namespace Avalonia.Themes.Fluent
+{
+ internal class IBitmapToImageConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value != null && value is IBitmap bm)
+ return new Image { Source=bm };
+
+ return null;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}