Skip to content

Commit

Permalink
Improve debugger experience (#27017)
Browse files Browse the repository at this point in the history
* add debugger display on controls

* more DebuggerDisplay

* add ", "

* Fix typo on SearchCommand

Co-authored-by: Gerald Versluis <gerald@verslu.is>

* fix typo in GetDebuggerDisplay

* remove wrong attribute

* fix typo in attribute

* code style

---------

Co-authored-by: Gerald Versluis <gerald@verslu.is>
  • Loading branch information
pictos and jfversluis authored Jan 26, 2025
1 parent 0f9dfdd commit 4504a68
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable disable
using System;
using System.Diagnostics;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/ActivityIndicator.xml" path="Type[@FullName='Microsoft.Maui.Controls.ActivityIndicator']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class ActivityIndicator : View, IColorElement, IElementConfiguration<ActivityIndicator>, IActivityIndicator
{
/// <summary>Bindable property for <see cref="IsRunning"/>.</summary>
Expand Down Expand Up @@ -40,5 +42,10 @@ public IPlatformElementConfiguration<T, ActivityIndicator> On<T>() where T : ICo
{
return _platformConfigurationRegistry.Value.On<T>();
}

private protected override string GetDebuggerDisplay()
{
return $"IsRunning = {IsRunning}, {base.GetDebuggerDisplay()}";
}
}
}
1 change: 1 addition & 0 deletions src/Controls/src/Core/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Button/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.Maui.Controls
/// <summary>
/// A button <see cref="View" /> that reacts to touch events.
/// </summary>
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class Button : View, IFontElement, ITextElement, IBorderElement, IButtonController, IElementConfiguration<Button>, IPaddingElement, IImageController, IViewController, IButtonElement, ICommandElement, IImageElement, IButton, ITextButton, IImageButton
{
const double DefaultSpacing = 10;
Expand Down Expand Up @@ -607,5 +608,10 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
=> throw new NotSupportedException();
}

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, Command = {Command}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/CheckBox/CheckBox.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable disable
using System;
using System.Diagnostics;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="Type[@FullName='Microsoft.Maui.Controls.CheckBox']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement, ICheckBox
{
readonly Lazy<PlatformConfigurationRegistry<CheckBox>> _platformConfigurationRegistry;
Expand Down Expand Up @@ -79,5 +81,10 @@ bool ICheckBox.IsChecked
get => IsChecked;
set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler);
}

private protected override string GetDebuggerDisplay()
{
return $"IsChecked = {IsChecked}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/ContentPage/ContentPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable

using System;
using System.Diagnostics;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.HotReload;
using Microsoft.Maui.Layouts;
Expand All @@ -9,6 +10,7 @@ namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/ContentPage.xml" path="Type[@FullName='Microsoft.Maui.Controls.ContentPage']/Docs/*" />
[ContentProperty("Content")]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class ContentPage : TemplatedPage, IContentView, HotReload.IHotReloadableView
{
/// <summary>Bindable property for <see cref="Content"/>.</summary>
Expand Down Expand Up @@ -147,5 +149,10 @@ Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightCons
{
return (this as ICrossPlatformLayout).CrossPlatformMeasure(widthConstraint, heightConstraint);
}

private protected override string GetDebuggerDisplay()
{
return $"Content = {Content}, BindingContext = {BindingContext}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/ContentView/ContentView.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#nullable disable
using System.Diagnostics;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/ContentView.xml" path="Type[@FullName='Microsoft.Maui.Controls.ContentView']/Docs/*" />
[ContentProperty("Content")]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class ContentView : TemplatedView, IContentView
{
/// <summary>Bindable property for <see cref="Content"/>.</summary>
Expand Down Expand Up @@ -46,5 +48,10 @@ internal override void SetChildInheritedBindingContext(Element child, object con
object IContentView.Content => Content;

IView IContentView.PresentedContent => ((this as IControlTemplated).TemplateRoot as IView) ?? Content;

private protected override string GetDebuggerDisplay()
{
return $"Content = {Content}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/DatePicker/DatePicker.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#nullable disable
using System;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/DatePicker.xml" path="Type[@FullName='Microsoft.Maui.Controls.DatePicker']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class DatePicker : View, IFontElement, ITextElement, IElementConfiguration<DatePicker>, IDatePicker
{
/// <summary>Bindable property for <see cref="Format"/>.</summary>
Expand Down Expand Up @@ -239,5 +241,10 @@ string IDatePicker.Format
get => Format;
set => SetValue(FormatProperty, value, SetterSpecificity.FromHandler);
}

private protected override string GetDebuggerDisplay()
{
return $"Date = {Date}, {base.GetDebuggerDisplay()}";
}
}
}
4 changes: 4 additions & 0 deletions src/Controls/src/Core/FlyoutPage/FlyoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,9 @@ double IFlyoutView.FlyoutWidth
#else
double IFlyoutView.FlyoutWidth => -1;
#endif
private protected override string GetDebuggerDisplay()
{
return $"DetailPage = {Detail}, FlyoutPage = {Flyout}, BindingContext = {BindingContext}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Image/Image.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable disable
using System;
using System.ComponentModel;
using System.Diagnostics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/Image.xml" path="Type[@FullName='Microsoft.Maui.Controls.Image']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class Image : View, IImageController, IElementConfiguration<Image>, IViewController, IImageElement, IImage
{
/// <summary>Bindable property for <see cref="Source"/>.</summary>
Expand Down Expand Up @@ -103,5 +105,10 @@ void IImageElement.RaiseImageSourcePropertyChanged() =>

void IImageSourcePart.UpdateIsLoading(bool isLoading) =>
IsLoading = isLoading;

private protected override string GetDebuggerDisplay()
{
return $"Source = {Source}, {base.GetDebuggerDisplay()}";
}
}
}
8 changes: 8 additions & 0 deletions src/Controls/src/Core/IndicatorView/IndicatorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;
Expand All @@ -10,6 +11,8 @@ namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/IndicatorView.xml" path="Type[@FullName='Microsoft.Maui.Controls.IndicatorView']/Docs/*" />
[ContentProperty(nameof(IndicatorLayout))]

[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class IndicatorView : TemplatedView, ITemplatedIndicatorView
{
const int DefaultPadding = 4;
Expand Down Expand Up @@ -193,5 +196,10 @@ int IIndicatorView.Position
get => Position;
set => SetValue(PositionProperty, value, SetterSpecificity.FromHandler);
}

private protected override string GetDebuggerDisplay()
{
return $"Position = {Position}, Count = {Count}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/InputView/InputView.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#nullable disable
using System;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/InputView.xml" path="Type[@FullName='Microsoft.Maui.Controls.InputView']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class InputView : View, IPlaceholderElement, ITextElement, ITextInput, IFontElement
{
/// <summary>Bindable property for <see cref="Text"/>.</summary>
Expand Down Expand Up @@ -271,5 +273,10 @@ string ITextInput.Text
get => Text;
set => SetValue(TextProperty, value, SetterSpecificity.FromHandler);
}

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, {base.GetDebuggerDisplay()}";
}
}
}
5 changes: 5 additions & 0 deletions src/Controls/src/Core/Items/ItemsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,10 @@ protected override void OnBindingContextChanged()
if (InternalItemsLayout is BindableObject bo)
SetInheritedBindingContext(bo, BindingContext);
}

private protected override string GetDebuggerDisplay()
{
return $"ItemsSource = {ItemsSource}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Label/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
Expand All @@ -12,6 +13,7 @@ namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/Label.xml" path="Type[@FullName='Microsoft.Maui.Controls.Label']/Docs/*" />
[ContentProperty(nameof(Text))]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class Label : View, IFontElement, ITextElement, ITextAlignmentElement, ILineHeightElement, IElementConfiguration<Label>, IDecorableTextElement, IPaddingElement, ILabel
{
/// <summary>Bindable property for <see cref="HorizontalTextAlignment"/>.</summary>
Expand Down Expand Up @@ -477,5 +479,10 @@ internal static bool TextChangedShouldInvalidateMeasure(Label label)
// The label may grow/shrink based on the constraints, so we need to invalidate.
return true;
}

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Layout/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls.Xaml.Diagnostics;
Expand All @@ -14,6 +15,7 @@ namespace Microsoft.Maui.Controls
/// Base class for layouts that allow you to arrange and group UI controls in your application.
/// </summary>
[ContentProperty(nameof(Children))]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public abstract partial class Layout : View, Maui.ILayout, IList<IView>, IBindableLayout, IPaddingElement, IVisualTreeElement, ISafeAreaView, IInputTransparentContainerElement
{
protected ILayoutManager _layoutManager;
Expand Down Expand Up @@ -383,5 +385,10 @@ static void OnCascadeInputTransparentPropertyChanged(BindableObject bindable, ob
layout.RefreshInputTransparentProperty();
}
}

private protected override string GetDebuggerDisplay()
{
return $"ChildCount = {Count}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -18,6 +19,7 @@ namespace Microsoft.Maui.Controls
/// </summary>
/// <remarks><see cref = "Page" /> is primarily a base class for more useful derived types. Objects that are derived from the <see cref="Page"/> class are most prominently used as the top level UI element in .NET MAUI applications. In addition to their role as the main pages of applications, <see cref="Page"/> objects and their descendants can be used with navigation classes, such as <see cref="NavigationPage"/> or <see cref="FlyoutPage"/>, among others, to provide rich user experiences that conform to the expected behaviors on each platform.
/// </remarks>
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement, ISafeAreaView, ISafeAreaView2, IView, ITitledElement, IToolbarElement
#if IOS
,IiOSPageSpecifics
Expand Down Expand Up @@ -938,5 +940,10 @@ protected virtual void OnNavigatedFrom(NavigatedFromEventArgs args) { }
/// <returns>The <see cref="Window"/> instance that parents the page.</returns>
public virtual Window GetParentWindow()
=> this.FindParentOfType<Window>();

private protected override string GetDebuggerDisplay()
{
return $"BindingContext = {BindingContext}, Title = {Title}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/Picker/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml;
Expand All @@ -13,6 +14,7 @@
namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/Picker.xml" path="Type[@FullName='Microsoft.Maui.Controls.Picker']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class Picker : View, IFontElement, ITextElement, ITextAlignmentElement, IElementConfiguration<Picker>, IPicker
{
/// <summary>Bindable property for <see cref="TextColor"/>.</summary>
Expand Down Expand Up @@ -460,5 +462,10 @@ string GetItem(int index)

return string.Empty;
}

private protected override string GetDebuggerDisplay()
{
return $"Items = {ItemsSource?.Count ?? 0}, SelectedItem = {SelectedItem}, {base.GetDebuggerDisplay()}";
}
}
}
7 changes: 7 additions & 0 deletions src/Controls/src/Core/ProgressBar/ProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable disable
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
Expand All @@ -8,6 +9,7 @@
namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/ProgressBar.xml" path="Type[@FullName='Microsoft.Maui.Controls.ProgressBar']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class ProgressBar : View, IElementConfiguration<ProgressBar>, IProgress
{
/// <summary>Bindable property for <see cref="ProgressColor"/>.</summary>
Expand Down Expand Up @@ -53,5 +55,10 @@ public IPlatformElementConfiguration<T, ProgressBar> On<T>() where T : IConfigPl
{
return _platformConfigurationRegistry.Value.On<T>();
}

private protected override string GetDebuggerDisplay()
{
return $"Progress = {Progress}, {base.GetDebuggerDisplay()}";
}
}
}
Loading

0 comments on commit 4504a68

Please sign in to comment.