Giter Club home page Giter Club logo

xamarin.forms.debugrainbows's Introduction

🌴 Looking for a .NET MAUI version? 🌴

We have you covered! Just check out this new version!

Xamarin.Forms.DebugRainbows

The package you didn't even know you needed!

Build status NuGet

Why DebugRainbows?

Have you ever had a piece of XAML code that didn't produce the layout you expected? Did you change background colors on certain elements to get an idea of where they are positioned? Admit it, you have and pretty much all of us have at some point. Either way, this is the package for you! It adds some nice colorful debug modes to your ContentPages or specific visual elements that lets you immediately see where all of your elements are located!

API Reference

Property What it does
GridLineColor Defines a color for the grid lines or blocks (depending on Inverse).
GridLineOpacity The opacity of the grid lines in the overlay.
GridLineWidth The width of the grid lines or between each block (depending on Inverse).
GridOrigin Where the first line is drawn. Either TopLeft or Center.
GridPadding Pads the entire overlay. Takes a Thickness object.
HorizontalSpacing Width between grid lines or the width of the blocks (depending on Inverse).
Inverse Either draws grid lines (false) or block view (true).
MajorGridLineColor When using major grid lines you can color them differently.
MajorGridLineInterval Defines the interval of when a major grid line should be drawn.
MajorGridLineOpacity The opacity of the major grid lines in the overlay.
MajorGridLineWidth The width of the major grid lines or space between block (depending on Inverse).
MakeGridRainbows Throws some instant joy into your overlays.
ShowColors Automatically gives every visual element a random background color.
ShowGrid Draws a customizable grid overlay used to help you align elements.
VerticalItemSize Height between grid lines or the height of the blocks (depending on Inverse).

How to use it?

The project is up on NuGet at the following URL:

https://www.nuget.org/packages/Xamarin.Forms.DebugRainbows

Install this package into your shared project and your platform specific projects. After that you're good to go! Simply add the namespace declaration and set the ShowColors or ShowGrid attached property to true!

XAML UI

Apply to an individual Xamarin.Forms.ContentPage

<ContentPage rainbows:DebugRainbow.ShowColors="true"
   xmlns="http://xamarin.com/schemas/2014/forms" 
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
   xmlns:rainbows="clr-namespace:Xamarin.Forms.DebugRainbows;assembly=Xamarin.Forms.DebugRainbows" 
   x:Class="MyNamespace.MainPage">
             
  ...
             
</ContentPage>

Apply to every Xamarin.Forms.ContentPage

In App.xaml, we can add a Style to our ResourceDictionary:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="MyNamespace.App"
             xmlns:rainbows="clr-namespace:Xamarin.Forms.DebugRainbows;assembly=Xamarin.Forms.DebugRainbows" >
    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="ContentPage" ApplyToDerivedTypes="True">
               <Setter Property="rainbows:DebugRainbow.ShowColors" Value="True" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Coded UI

Apply to an individual Xamarin.Forms.ContentPage

public MyContentPage : ContentPage
{
    Xamarin.Forms.DebugRainbows.DebugRainbow.SetShowColors(this, true);
}

Apply to every Xamarin.Forms.ContentPage

public class App : Xamarin.Forms.Application
{
    public App()
    {
    
#if DEBUG
        EnableDebugRainbows(true);
#endif
        
        //...
    });
    
    void EnableDebugRainbows(bool shouldUseDebugRainbows)
    {
        Resources.Add(new Style(typeof(ContentPage))
        {
            ApplyToDerivedTypes = true,
            Setters = {
                new Setter
                {
                    Property = Xamarin.Forms.DebugRainbows.DebugRainbow.ShowColorsProperty,
                    Value = shouldUseDebugRainbows
                }
            }
        });
    }
 }

xamarin.forms.debugrainbows's People

Contributors

brminnick avatar jamesmontemagno avatar jslachta avatar jsuarezruiz avatar sthewissen avatar ylinssen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xamarin.forms.debugrainbows's Issues

Maui

Hi,

Do you plan to support dotnet maui ?
Or maybe there is already an alternative ?

Thank you for this nice library !

Profiler Helper

Let's continue increasing the possibilities of the library. The idea would be:
Create a new Helper that shows:

  • Memory used by the application (we could also show higher peak usage, etc.).
  • Number of elements of the view (the number of elements in the visual tree).
  • Etc

Setup through C# code behind?

Hi,

I have create a custom ContentPage that acts as a base page for the majority of the pages in the app.
I have create a property called IsDebug, so that any pages that is based on this content page can simply change the IsDebug to true and it will turn on the debug rainbow.

In the BasePage I have this -
Xaml -

xmlns:rainbows="clr-namespace:Xamarin.Forms.DebugRainbows;assembly=Xamarin.Forms.DebugRainbows"
rainbows:DebugRainbow.IsDebug="False"

Code behind -

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BasePage : ContentPage
{
    public IList<View> BasePageContent => BaseContent.Children;

    public static readonly BindableProperty IsDebugProperty = BindableProperty.Create(nameof(IsDebug), typeof(bool), typeof(BasePage), false, defaultBindingMode: BindingMode.OneWay, propertyChanged: IsDebugChanged);
    public bool IsDebug
    {
        get => (bool)GetValue(IsDebugProperty);
        set => SetValue(IsDebugProperty, value);
    }
    public BasePage()
    {
        InitializeComponent();
    }


    private static void IsDebugChanged(BindableObject bindable, object oldValue, object newValue)
    {

        if (bindable != null && bindable is BasePage basePage)
        {
            // Enable or disable rainbow debug

        }
    }
}

Issue is im not sure how to set the value of rainbows:DebugRainbow.IsDebug="False" from the code behind.

Enable/Disable DebugRainbows at runtime

Is there any way to enable or disable DebugRainbows for all ContentPages and ContentViews at runtime. I tried to use that approach with MergedDictionaries like in that sample:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/theming

but it doesn't work- I created a Debug.xaml / Debug.xaml.cs and a NoDebug.xaml & NoDebug.xaml.cs like the Dark and Light theme in the sample. Then I used similar code to switch the Debug and NoDebug ResourceDictionary. But no effect. Ah to mention. In Debug.xaml I set Value to true, in NoDebug.xaml to false like

Debug

<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
               <Setter Property="rainbows:DebugRainbow.ShowColors" Value="True" />
            </Style>

NoDebug

<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
               <Setter Property="rainbows:DebugRainbow.ShowColors" Value="False" />
            </Style>

Thanks in advance if you have a running sample or a hint if it's possible to do the switch at runtime.

Not working in iOS designer ?

I have installed your component, and as it works fine in my simulator it does not show on the iOS designer.

Is that not possible ?

Forms 4 only?

Am I correct in assuming that it is running on forms 4.xxx only?

Tap Border Helper

The idea is similar to the actual now, draw the border (or background) of a control with a color to see exactly its position and size. The difference is that, instead of drawing all, we are only going to draw that control over a special tap is made (Example: triple tap).

[Feature] Make debug grid start from center

Add a property for the overlay grid to start from the horizontal and vertical center with a Major grid line (if used) and space itself out to the top, bottom, left and right. Probably best off making a property named GridOrigin with an enum containing TopLeft and Center for now. Can always add more if needed.

Read.me not updated or not synchroised with Release nuget

Read.me

<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="rainbows:DebugRainbow.ShowColors" Value="True" />
</Style>

On nuget 1.0.16 I used and it worked

<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="rainbows:DebugRainbow.IsDebug" Value="True" />
</Style>

ShowColors is gone and IsDebug is accessible from XAML.

Doesn't work in toolbar Clicked event

Trying to set some toolbar items to help make it easier to debug.
The below code has been added to a base page.

In the page constructor I've added this -

#if DEBUG
            ToolbarItem rainbowToggle = new ToolbarItem
            {
                Text = "Rainbow",
                Order = ToolbarItemOrder.Secondary,
                Priority = 1
            };
            rainbowToggle.Clicked += RainbowToggleClicked;
            this.ToolbarItems.Add(rainbowToggle);
#endif

Then the clicked event is this (will add a property to toggle the option once it works) -

#if DEBUG

        void RainbowToggleClicked(object sender, EventArgs e)
        {
            DebugRainbow.SetShowColors(this, true);
        }
#endif

The DebugRainbow.SetShowColors() line is hit without error but none of the colours changes. Adding DebugRainbow.SetShowColors(this, true); to the constructor works fine.

Same issue with SetShowGrid()

Add margin/padding visualization

That's great! This is really a productivity power tool, and it would be nice if it could support display margin border padding width height value。
image

Show grid lines on NavigationBar and TabBar

Hello,

I work on a Xamarin.Forms.Shall app based on a TabBar. My pages also contain a NavigationBar customized by TitleView and a StatusBar.

When I launch the app, the grid lines are not displayed over the NavigationBar and TabBar.

Is it normal?

It's the same thing on iOS and Android.

I've attached a screenshot to illustrate my request.
Simulator Screen Shot - iPhone 12 Pro - 2020-11-19 at 14 47 14

Option to activate debug mode in all pages

Have you ever thought about the possibility to enable the Debug Mode in the whole app, setting random colors for every view in every page without the need of adding DebugRainbow.IsDebug="true in the individual pages?

That could be a option you can enable in App.xml.cs, by statically calling some method or variable of DebugRainbow to set the debug in all pages, and it would run whenever a new page is open. Is that possible?

If you could give me directions I may try and create a pull request over the next days. ;)

error XA2002: Can not resolve reference in Android Project

By just adding the NuGet to my Shared Project iget the following Error in my Android Project:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1866,2): error XA2002: Can not resolve reference: Xamarin.Forms.DebugRainbows, referenced by XYZ. Please add a NuGet package or assembly reference for Xamarin.Forms.DebugRainbows, or remove the reference to XYZ.

If i add the Nuget to Android too it works. That should not be needed, right?

Change description

the correct is rainbows:DebugRainbow.IsDebug="true" not rainbows:DebugRainbow.ShowColors="true"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.