@ -20,12 +20,13 @@ namespace Avalonia.Diagnostics.ViewModels
_ valueFrame = valueFrame ;
IsVisible = true ;
Description = ( _ valueFrame . Type , _ valueFrame . Description ) switch
var source = SourceToString ( _ valueFrame . Source ) ;
Description = ( _ valueFrame . Type , source ) switch
{
( IValueFrameDiagnostic . FrameType . Local , _ ) = > "Local Values " + _ valueFrame . Description ,
( IValueFrameDiagnostic . FrameType . Template , _ ) = > "Template " + _ valueFrame . Description ,
( IValueFrameDiagnostic . FrameType . Theme , _ ) = > "Theme " + _ valueFrame . Description ,
( _ , { Length : > 0 } ) = > _ valueFrame . Description ,
( IValueFrameDiagnostic . FrameType . Local , _ ) = > "Local Values " + source ,
( IValueFrameDiagnostic . FrameType . Template , _ ) = > "Template " + source ,
( IValueFrameDiagnostic . FrameType . Theme , _ ) = > "Theme " + source ,
( _ , { Length : > 0 } ) = > source ,
_ = > _ valueFrame . Priority . ToString ( )
} ;
@ -113,5 +114,40 @@ namespace Avalonia.Diagnostics.ViewModels
return false ;
}
private string? SourceToString ( object? source )
{
if ( source is Style style )
{
StyleBase ? currentStyle = style ;
var selectors = new Stack < string > ( ) ;
while ( currentStyle is not null )
{
if ( currentStyle is Style { Selector : { } selector } )
{
selectors . Push ( selector . ToString ( ) ) ;
}
if ( currentStyle is ControlTheme theme )
{
selectors . Push ( "Theme " + theme . TargetType ? . Name ) ;
}
currentStyle = currentStyle . Parent as StyleBase ;
}
return string . Concat ( selectors ) . Replace ( "^" , "" ) ;
}
else if ( source is ControlTheme controlTheme )
{
return controlTheme . TargetType ? . Name ;
}
else if ( source is StyledElement styledElement )
{
return styledElement . StyleKey ? . Name ;
}
return null ;
}
}
}