Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Add API for programmatically checking if running in design mode #1731

Closed
therealjohn opened this issue Jan 29, 2018 · 3 comments

Comments

@therealjohn
Copy link

Rationale

User’s desire a way to specify code that should only run when their code is running in a designer context such as Previewer or Live Player.

Implementation

// In Xamarin.Forms
pubic static class DesignMode
{
    public static bool DesignModeEnabled { get; set; }
}
// Example usage 
if(Xamarin.Forms.DesignMode.DesignModeEnabled)
{
    // do something special
}

The property should be considered to have a public setter so that third-party tools can also mark this as true when they would prefer to. i.e. LiveXaml, GorillaPlayer, etc. may want to set this to true so users can do something special in those contexts. Or, perhaps it's better to make this read only and make some static method for enabling it. i.e.

Xamarin.Forms.DesignMode.EnableDesignMode()

See UWP documentation.

Expected Result

DesignModeEnabled would return true when code is running in a preview or design-time tool. Otherwise, false.

Android

Nothing specific for Android.

iOS

Nothing specific for iOS.

UWP

Nothing specific for UWP

Implications for CSS

None that I am aware of.

Backward Compatibility

Uncertain, but it seems a new API like this would have little to no backwards compatibility issues.

Difficulty: Easy

There may be some additional coordination required with the designer team for a few additions for the previewer to work with this. Otherwise, it should be simple to implement.

@StephaneDelcroix
Copy link
Member

the implications are far from "easy"

@therealjohn
Copy link
Author

@StephaneDelcroix Can you elaborate? I've been told that this "should be easy" so I was repeating that. I'd be curious to know further details in either direction.

therealjohn added a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 8, 2018
Provides a static boolean that can be checked by application authors whether their app is running in a tool considered to be a designer or previewer. Tool authors can set this value to true whenever the app is running in that context or not.

Resolves xamarin#1731
therealjohn added a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 8, 2018
Provides a static boolean that can be checked by application authors whether their app is running in a tool considered to be a designer or previewer. Tool authors can set this value to true whenever the app is running in that context or not.

Resolves xamarin#1731
therealjohn added a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 8, 2018
Provides a static boolean for application authors to check if their app is running in a visual designer or previewer.

Tools can set this value when running the app in a designer or previewer context.

Resolves xamarin#1731
@therealjohn
Copy link
Author

I started this in #1844. The intent of this F100 issue was just for programmatic checks and did not cover things like d:DesignHeight etc. I believe those enhancements are more complex and out of scope for this enhancement.

therealjohn added a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 21, 2018
Provides a static boolean for application authors to check if their app is running in a visual designer or previewer.

Tools can set this value when running the app in a designer or previewer context.

Resolves xamarin#1731
therealjohn pushed a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 23, 2018
* Adds DesignMode class

Provides a static boolean for application authors to check if their app is running in a visual designer or previewer.

Tools can set this value when running the app in a designer or previewer context.

Resolves xamarin#1731

* Enable design mode when we use the design mode APIs

These are the two supported APIs for design mode rendering,
so to ensure the DesignMode boolean is set correctly for
all existing releases of VS/VSMac, let's set it to true
whenever something connects to the design mode rendering
APIs.
alanmcgovern added a commit that referenced this issue Feb 23, 2018
* Adds DesignMode class

Provides a static boolean for application authors to check if their app is running in a visual designer or previewer.

Tools can set this value when running the app in a designer or previewer context.

Resolves #1731

* Enable design mode when we use the design mode APIs

These are the two supported APIs for design mode rendering,
so to ensure the DesignMode boolean is set correctly for
all existing releases of VS/VSMac, let's set it to true
whenever something connects to the design mode rendering
APIs.
therealjohn pushed a commit to therealjohn/Xamarin.Forms that referenced this issue Feb 23, 2018
* Adds DesignMode class

Provides a static boolean for application authors to check if their app is running in a visual designer or previewer.

Tools can set this value when running the app in a designer or previewer context.

Resolves xamarin#1731

* Enable design mode when we use the design mode APIs

These are the two supported APIs for design mode rendering,
so to ensure the DesignMode boolean is set correctly for
all existing releases of VS/VSMac, let's set it to true
whenever something connects to the design mode rendering
APIs.
StephaneDelcroix added a commit that referenced this issue Mar 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants