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

[X] Design time properties #4743

Merged
merged 1 commit into from
Dec 20, 2018
Merged

[X] Design time properties #4743

merged 1 commit into from
Dec 20, 2018

Conversation

StephaneDelcroix
Copy link
Member

@StephaneDelcroix StephaneDelcroix commented Dec 14, 2018

An alternate xaml resource file provider can request the XamlLoader to
not ignore normally ignored properties in prebuilt XF design xmlns, as
in the following snippet:

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://xamarin.com/schemas/2014/forms/design"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
  <Label d:Text="Bar" Text="Foo" x:Name="label" />
</ContentPage>

The d: should be the prefix used by default for this, but any other
prefix will do too.

The d:Text property maps to the exact same property as Text, as the
XmllnsDefinitionAttributes are identical (that's convenient from a Intelisense
point of view), but, when (and only when) instructed by a provided Xaml resource
loader, the d:Text will override the Text property.

This works with virtually all properties defined on built-in Xamarin.Forms
controls, but it doesn't mean it's a sane idea to try to assign design value
to all existing properties.

The API for setting the ResourceLoader had to change, and instead of taking
pre-defined arguments, it accepts and returns query and response types. This
is slightly less convenient to invoke through reflection, but way more easy
to extend in the future.

As a side note, I'm quite proud, and thankful, of the work done by that 5-people
2-hours brainstorming-meeting that came up with the new name for the now
deprecated ResourceProvider.

VS bug #783304

@StephaneDelcroix StephaneDelcroix changed the base branch from master to 3.5.0 December 14, 2018 20:00
@samhouts samhouts added this to In Review in v3.5.0 Dec 14, 2018
@StephaneDelcroix StephaneDelcroix added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Dec 17, 2018
@samhouts samhouts moved this from In Review to In Progress in v3.5.0 Dec 17, 2018
@StephaneDelcroix StephaneDelcroix removed the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Dec 17, 2018
@StephaneDelcroix StephaneDelcroix changed the title [wip] designtime props [X] Design time properties Dec 17, 2018
StephaneDelcroix added a commit that referenced this pull request Dec 17, 2018
be ready for when we'll merge #4743
@StephaneDelcroix StephaneDelcroix mentioned this pull request Dec 17, 2018
3 tasks
@samhouts samhouts moved this from In Progress to In Review in v3.5.0 Dec 17, 2018
public static class ResourceLoader
{
static Func<AssemblyName, string, string> resourceProvider;

[Obsolete("You shouldn't have used this one to begin with, don't use the other one either")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 😄

Xamarin.Forms.Xaml/PruneIgnoredNodesVisitor.cs Outdated Show resolved Hide resolved
An alternate xaml resource file provider can request the XamlLoader to
_not_ ignore normally ignored properties in prebuilt XF design xmlns, as
in the following snippet:

```xaml
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms""
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml""
    xmlns:d="http://xamarin.com/schemas/2014/forms/design""
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006""
    mc:Ignorable="d"">
  <Label d:Text="Bar" Text="Foo" x:Name="label" />
</ContentPage>
```

The `d:` should be the prefix used by default for this, but any other
prefix will do too.

The `d:Text` property maps to the exact same property as `Text`, as the
XmllnsDefinitionAttributes are identical (that's convenient from a Intelisense
point of view), but, when (and only when) instructed by a provided Xaml resource
loader, the `d:Text` will override the `Text` property.

This works with virtually all properties defined on built-in Xamarin.Forms
controls, but it doesn't mean it's a sane idea to try to assign design value
to all existing properties.

The APi ofr setting the ResourceLoader had to change, and instead of taking
pre-defined arguments, it accepts and returns query and response types. This
is slightly less convenient to invoke through reflection, but way more easy
to extend in the future.
@StephaneDelcroix StephaneDelcroix merged commit a206fa0 into 3.5.0 Dec 20, 2018
v3.5.0 automation moved this from In Review to Done Dec 20, 2018
StephaneDelcroix added a commit that referenced this pull request Dec 20, 2018
be ready for when we'll merge #4743
@samhouts samhouts added this to the 3.5.0 milestone Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
v3.5.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants