mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model debugger - Display ToString of object if overridden
This commit is contained in:
parent
6c41a6b1f2
commit
a3906e3fe3
@ -8,20 +8,35 @@ namespace Artemis.UI.Shared
|
||||
public class DataModelPropertiesViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
private Type _displayValueType;
|
||||
private object _displayValue;
|
||||
|
||||
internal DataModelPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Type DisplayValueType
|
||||
{
|
||||
get => _displayValueType;
|
||||
set => SetAndNotify(ref _displayValueType, value);
|
||||
}
|
||||
|
||||
public object DisplayValue
|
||||
{
|
||||
get => _displayValue;
|
||||
set => SetAndNotify(ref _displayValue, value);
|
||||
}
|
||||
|
||||
public override void Update(IDataModelUIService dataModelUIService)
|
||||
{
|
||||
DisplayValueType = DataModelPath?.GetPropertyType();
|
||||
|
||||
// Only set a display value if ToString returns useful information and not just the type name
|
||||
object currentValue = GetCurrentValue();
|
||||
if (currentValue != null && currentValue.ToString() != currentValue.GetType().ToString())
|
||||
DisplayValue = currentValue.ToString();
|
||||
else
|
||||
DisplayValue = null;
|
||||
|
||||
// Always populate properties
|
||||
PopulateProperties(dataModelUIService);
|
||||
|
||||
@ -35,6 +50,8 @@ namespace Artemis.UI.Shared
|
||||
|
||||
public override object GetCurrentValue()
|
||||
{
|
||||
if (Parent == null)
|
||||
return null;
|
||||
return Parent.IsRootViewModel ? DataModel : base.GetCurrentValue();
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,18 @@
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<DataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}">
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" ToolTipService.ShowOnDisabled="True"/>
|
||||
<Grid ToolTip="{Binding PropertyDescription.Description}" ToolTipService.ShowOnDisabled="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Value description -->
|
||||
<TextBlock Grid.Column="0" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" ToolTipService.ShowOnDisabled="True"/>
|
||||
|
||||
<!-- Value display -->
|
||||
<TextBlock Grid.Column="1" Text="{Binding DisplayValue}" HorizontalAlignment="Right" FontFamily="Consolas" Margin="15 0.5 0 0"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type dataModel:DataModelListViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
||||
@ -65,6 +65,7 @@
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{Binding Children}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
@ -72,6 +73,10 @@
|
||||
<Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding DisplayValue}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user