Browse Source

Merge remote-tracking branch 'origin/master' into osx-nswindow-refactor

pull/8078/head
Dan Walmsley 5 years ago
parent
commit
bc75798b09
  1. 64
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
  2. 41
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
  3. 3
      src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml
  4. 28
      src/Avalonia.Themes.Default/IBitmapToImageConverter.cs
  5. 7
      src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml
  6. 28
      src/Avalonia.Themes.Fluent/IBitmapToImageConverter.cs

64
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

41
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));
}
}

3
src/Avalonia.Themes.Default/Controls/NativeMenuBar.xaml

@ -4,6 +4,7 @@
Selector="NativeMenuBar">
<Style.Resources>
<local:InverseBooleanValueConverter x:Key="AvaloniaThemesDefaultNativeMenuBarInverseBooleanValueConverter" Default="True"/>
<local:IBitmapToImageConverter x:Key="AvaloniaThemesDefaultNativeMenuBarIBitmapToImageConverterr"/>
</Style.Resources>
<Setter Property="Template">
<ControlTemplate>
@ -18,6 +19,8 @@
<Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
<Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/>
<!--NativeMenuItem is IBitmap and MenuItem is Image-->
<Setter Property="Icon" Value="{Binding Icon , Converter={StaticResource AvaloniaThemesDefaultNativeMenuBarIBitmapToImageConverterr}}"/>
</Style>
</Menu.Styles>
</Menu>

28
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();
}
}
}

7
src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml

@ -4,12 +4,13 @@
x:CompileBindings="True"
Selector="NativeMenuBar">
<Style.Resources>
<local:InverseBooleanValueConverter x:Key="AvaloniaThemesDefaultNativeMenuBarInverseBooleanValueConverter" Default="True"/>
<local:InverseBooleanValueConverter x:Key="AvaloniaThemesFluentNativeMenuBarInverseBooleanValueConverter" Default="True"/>
<local:IBitmapToImageConverter x:Key="AvaloniaThemesFluentNativeMenuBarIBitmapToImageConverter"/>
</Style.Resources>
<Setter Property="Template">
<ControlTemplate>
<Menu
IsVisible="{Binding $parent[TopLevel].(NativeMenu.IsNativeMenuExported), Converter={StaticResource AvaloniaThemesDefaultNativeMenuBarInverseBooleanValueConverter}}"
IsVisible="{Binding $parent[TopLevel].(NativeMenu.IsNativeMenuExported), Converter={StaticResource AvaloniaThemesFluentNativeMenuBarInverseBooleanValueConverter}}"
Items="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}">
<Menu.Styles>
<Style x:CompileBindings="False" Selector="MenuItem">
@ -19,6 +20,8 @@
<Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
<Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/>
<!--NativeMenuItem is IBitmap and MenuItem is Image-->
<Setter Property="Icon" Value="{Binding Icon , Converter={StaticResource AvaloniaThemesFluentNativeMenuBarIBitmapToImageConverter}}"/>
</Style>
</Menu.Styles>
</Menu>

28
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();
}
}
}
Loading…
Cancel
Save