GithubHelp home page GithubHelp logo

vincenth-net / csharpformarkup Goto Github PK

View Code? Open in Web Editor NEW
723.0 36.0 44.0 18.07 MB

Concise, declarative C# UI markup for .NET browser / native UI frameworks

License: MIT License

C# 100.00% JavaScript 0.01% PowerShell 0.01% CSS 0.01%
xamarin-forms xaml csharp readability ide-support winui3 maui xamarin uno-platform wpf

csharpformarkup's Introduction

C# Markup 2

Concise next-gen C# Markup for .NET UI frameworks

C# Markup 2 for Uno Platform

C# Markup 2 supports multiple UI frameworks, including the excellent Uno Platform.

If you don't know Uno, I recommend you check them out; Uno is one of the best and most mature .NET UI frameworks, it offers an impressive breadth of features that will have your back when you need to create real-world production apps end2end, fast.

Quick play-around

dotnet new install Uno.Templates
dotnet new install Modern.CSharp.Templates

md UnoCSharpMarkup2
cd UnoCSharpMarkup2

dotnet new unoapp
dotnet new mcs-uno-markup2 --presentation mvux

Markup options at a glance - good for everyone!

Uno Platform supports XAML but recently has embraced C# UI as well with Uno C# Markup. C# Markup 2 adds another option that goes above and beyond what gen-1 C# Markup variants offer.

It's good to have options - everyone wins: devs get the experience that they like best, and the UI framework gains more adoption. Check it out and pick what you like!

As a first impression, here's a quick side-by-side comparison: XAML - C# Markup 2 - Uno C# Markup

Enjoy a Flutter-like UI development experience with C# Markup 2:

  • Build .NET applications fully in C#
  • Unclutter your markup - while reading and writing.
    • C# Markup 2 goes above and beyond gen 1 C# Markup approaches (e.g. Maui or Uno) to eliminate a lot of verbosity: no more endless repetitions of new , HorizontalAlignment = HorizontalAlignment.Center, () => or nameof(), no more specifying for each and every TextBlock binding that yes, you want to bind to the Text property...
    • Separated markup namespaces eliminate intellisense pollution, allow quick discovery and encourage clean separation of markup and logic: no more intellisense lists where you have to search in a sea of irrelevant options for the few that you are interested in. See only Markup API's while editing MyPage.cs, see UI framework and other API's while editing MyPage.logic.cs.
  • Target browsers and native desktop / mobile
  • Use existing UI frameworks. Mature or bleeding edge is your choice: WPF, WinUI 3 for Windows App SDK and Uno Platform. Coming: AvaloniaUI, Maui, possibly Blazor.
  • Use the built-in MVVM support - or any other update model that supports your UI framework (e.g. Uno's MVUX or ReactiveUI)
  • Use for part or all of your application UI
  • Designed to handle large UI fast: practically allocation-free, no reflection, efficient C#

No XAML / HTML / JavaScript / CSS required. No engine or layers to get in your way.

Markup Example Flutter Page

NuGet
Nuget (with prereleases)
Nuget (with prereleases)
Nuget (with prereleases)
Nuget (with prereleases)
Nuget (with prereleases)
Nuget (with prereleases)
Nuget (with prereleases)

Nuget (with prereleases)

Chat (if needed, join DotNetEvolution first)
Discord
The best place to ask questions or help!

Getting Started

Looking for C# Markup 1? Find it here

News

Dec 21, 2023

New C# Markup 2 templates for Uno Platform 5

In addition to some new C# Markup 2 methods, today's release adds support for the new C# Markup 2 templates for Uno Platform 5: an updated mcs-uno-markup2 template, and a new mcs-uno-view template.

  • Enjoy improved frictionless startup for both existing and new Uno solutions - whether created with Uno's dotnet new unoapp template or with the Uno solution wizard for Visual Studio
  • Full support for .NET 8 / .NET 7, as well as model types MVUX / MVVM / none
  • The new mcs-uno-view template is used by the convenient New-View.ps1 script, which is included in mcs-uno-markup2
  • Templates are now pre-structured in accordance with best practices for maintainability and code reuse of C# Markup 2 UI.

Nov 18, 2023

2.3 Release is GA - adds support for .NET 8, Uno 5 plus 5 Uno Libraries!

This release is fully updated to the awesome Uno 5 release and .NET 8 GA. You can use the Uno Solution Wizard for Visual Studio and add a C# Markup 2 project to it at any time with one command. All Uno wizard customizations are supported: combine C# Markup 2 with MVUX or MVVM, XAML or Uno C# Markup, use Uno Navigation extensions, and target .NET 8 or .NET 7. All Uno target platforms are supported.

A brand new dotnet new C# Markup 2 project template gets you going in no time - carefully optimized for an optimal developer experience: uncluttered solution explorer view, automatic file grouping of markup and logic files, uncluttered markup source, focused intellisense, clear starting points for markup extensions in your code, plus fast hot reload - both automatic and with a hot reload button overlay in debug mode, for the platforms that your IDE can hot reload but cannot (yet) update the UI automatically.

Enjoy general C# Markup 2 improvements, plus C# Markup 2 API's for 5 additional Uno libraries:

The getting started is fully up to date. Examples in this repo and this readme will be updated soon to show off the new features.

NJoy concise C# Markup!

Nov 1, 2023

2.3 Preview Release adds 5 Uno Libraries!

Enjoy general C# Markup 2 improvements, plus C# Markup 2 API's for 5 additional Uno libraries:

  • Support for Uno's UI toolkit, Reactive and Navigation extensions
  • Support for the awesome LiveCharts2
  • All ThemeResources searchable in C# intellisense, strongly typed
  • Automatic UI update on C# hot reload
  • A development tools overlay

You can try this today - see the NuGets listed above. Documentation of the new features plus a new getting started guide is coming with the next release - soon!

June 27, 2023

2.2 Release & start of .NET MAUI support

  • Release 2.2 is out! Enjoy this polished release for Windows App SDK, Uno Platform and WPF.
  • As the poll results indicated, C# Markup 2 support for .NET MAUI is most wanted.
    Implementation has started!

March 25, 2023

Poll results are in! And the winner is...

The March 2023 poll results on what to build next for C# Markup 2 are in!

A surprise addition was the ask for C# Markup 2 for Avalonia UI in the replies; it got a big response that catapulted it into a very close 2nd place.

Here are the results for the poll including the likes for "Other" options Blazor and AvaloniaUI:

Poll202303

And the winner is: C# Markup 2 for MAUI!
Watch and star this repo to catch the release; you can also watch #CSharpForMarkup tweets for progress. Thanks for your response!

Feb 28, 2023

Major Release - C# Markup 2 version 2.0 for WinUI 3!

C# Markup 2 version 2.0 for WinUI 3 is here! Completely updated to .NET 7, C# 11 and the latest Windows App SDK and Uno Platform. With many improvements including 6 supported target platforms, C# hot reload support and dotnet new project templates.

Brought to you by Applicita

Special thanks go to Applicita for making this release possible; it's inspiring to see a company support OSS in this way (Applicita also open-sourced several other useful libraries)

More on what's new in this release here.

Feb 16, 2023

A new release of C# Markup 2 for WinUI 3 and Uno Platform is coming in Feb 2023

Updated to .NET 7, C# 11 and the latest Windows App SDK and Uno Platform. With many improvements - including C# hot reload support and a dotnet new project template. Watch this space!

April 14, 2022

New 0.8 release: adds ControlTemplate support and Style improvements!

See here and here for the full list of improvements

February 15, 2022

New 0.6 release: adds WPF and many improvements!

See here for the full list of improvements

November 30, 2021

C# Markup 2 announced at UNOCONF 2021!

This first preview targets WinUI 3 and Uno Platform - including browser webassembly - with C# 10 and .NET 6. It supports .NET Hot Reload for a fast inner dev loop.

See the C# Markup 2 announcement at UNOCONF 2021: UNOCONF Announces Csharp Markup 2

Getting started for WPF

  1. Clone this repo
  2. Open CSharpMarkup.Wpf.Examples.sln and explore the source for the example pages. Note how page markup and page logic are separated in partial class files, and integrated with Build(), Assign() and Invoke().
  3. .NET Hot Reload is supported; edit and save the page markup in VS 2022 while debugging to see instant updates
  4. To learn how to use C# Markup 2, read the features description below and experiment in the example app
  5. To build your own app, reference Nuget (with prereleases) from a .NET 6 WPF project and create the C# Markup UI windows, pages etc in that project. Note that for existing apps you can reference (WPF / class library) projects that target older .NET versions from the .NET 6 project, so you can add C# Markup UI to your app without having to migrate existing logic and/or WPF UI to .NET 6 and C# 10.

Getting started for WinUI 3 and Windows App SDK / Uno Platform

  1. First check if your development environment is ready:

  2. Either choose an existing Uno Platform 5 solution, or create a new one with the Uno Platform Template Wizard or the dotnet new unoapp template. Feel free to select any options; C# Markup 2 fully supports Uno 5 with .NET 8 or .NET 7, MVUX or MVVM, XAML or Uno C# Markup, on all target platforms.

  3. Install the latest Modern.CSharp.Templates for dotnet new to get these templates for Windows App SDK, Uno Platform and more

    dotnet new install Modern.CSharp.Templates

    To see help about the template parameters:

    dotnet new mcs-uno-markup2 -h
  4. Add a C# Markup 2 project to the Uno Platform solution, e.g.:

    cd C:\Repos\UnoApp1
    dotnet new mcs-uno-markup2 --appRootNamespace InnoWvate.UnoApp1 --presentation mvux --allow-scripts Yes

    This will:

    • Add a new project UnoApp1.Presentation to the solution, with a working example:

      • Pages
      • Models of the specified type (in above example MVUX)
      • Navigation
      • A New-View.ps1 script to quickly add more pages and models
      • A Readme.md with instructions on how to get started quickly

      The Presentation project is pre-structured for maintainability in accordance with best practices for C# Markup UI

    • Add NuGet package references to the Presentation project

    • Add a reference to the Presentation project in the UnoApp1 project

    Note that you can use the --name parameter of dotnet new to specify the name of your existing Uno project, if that differs from the solution folder name (in above example, UnoApp1). The specified name will be used with the .Presentation suffix for the new project as well.

  5. Open or reload the Uno solution and follow the steps in the Readme.md of the Presentation project to get started.

To learn how to use C# Markup 2, read the features description below.

(note that the example app in this repo is somewhat outdated - this will updated shortly)

Features

C# Markup 2 contains a full declarative, fluent API for existing UI frameworks. It surfaces virtually every layout, view and property, including attached properties, and includes full inline documentation that links each markup helper / parameter to the inline documentation for the underlying UI object / property.

The rich UI frameworks that C# Markup 2 surfaces can contain as much as 500+ UI object types. E.g. layouts, views and styles, but also brushes, rich text elements, drawing primitives, transformations, animations, visual states and more. In addition C# Markup offers powerful and concise convenience API's for layout, bindings, convertors, templates and more.

  • When targeting Windows Desktop, the WinUI API from the Windows App SDK is surfaced (without any dependency on Uno Platform).
  • When targeting Uno Platform, the Uno.WinUI API is surfaced (atm only webassembly is tested, but any Uno target platform that can support .NET 6 and C# 10 should work)
  • When targeting WPF, the WPF API is surfaced.

Basic markup anatomy

Layouts, views, properties and property values look like this:
Markup Basic Anatomy
All properties can be set with extension methods: properties defined on the view type or it's base types, as well as attached properties.

Properties that are defined directly on the view type can alternatively be set with named parameters:
Markup View Defined Properties
This is mainly useful for properties that take primitive types.

Properties that take enum values have extension methods so the enum name does not have to be repeated
(as in TextAlignment: TextAlignment.Center):
Markup Property Enum Values

Attached property names are prefixed with the defining type plus underscore:
Markup Attached Properties

You can set multiple attached property values for the same defining type in one call:
Markup Attached Properties

In addition to this, there are convenience overloads for some view types with just the most commonly used parameters:
Markup View Convenience Overload

Property value converters

Implicit converters are provided in the to subnamespace for common property value types:
Markup View Convenience Overload

These are:

  • All converters that accept string values, as specified by the UI framework with the TypeConverter attribute
    Note that WinUI 3 Desktop does not use this attribute, but Uno Platform and WPF do.
  • Additional manual converters that also accept other types than string, including tuples if more than one value is expected. E.g.:
    Markup View Convenience Overload
    Allows you to specify:
    Button() .CornerRadius (2.5) or
    Button() .CornerRadius ((2.5, 0, 2.5, 0))

An example using to.Point:

Button() .Background (RadialGradientBrush (Center: (50, 50), GradientOrigin: (100, 50)))

An example using to.TimeSpan and to.Duration:

ColorAnimation (BeginTime: "0:0:5", Duration: 2.5)

In many cases the inline documentation on the to. type describes the supported values and formatting; especially for strings this can avoid guesswork.

Styles

Styles can be assigned like this:
Markup Style Usage

And defined like this:
Markup Style Definition

In WPF you can bind a style setter value (WinUI 3 does not support this):
Markup Style Setter Binding

Templates

A DataTemplate is passed in as a Func<UIElement>:
Markup Templates

A ControlTemplate can be created like this:
Markup Templates

  • The .BindTemplate() method lets you bind template properties to the templated parent
  • The targetType parameter is optional
  • b here is a null-valued static UI_Button field. In this example it only serves to demonstrate one way to get intellisense when editing binding expressions for a Button; see Binding power for details.

Here is how you can use a ControlTemplate in an implicit or explicit Style:
Markup Templates

Enums for Grid rows and columns

You can use enums instead of numbers for Grid rows and colums. This improves readability and saves you from manually renumbering rows and columns when adding/removing/reordering them
Markup Enums For Grid Rows Columns

Markup Enums For Grid Rows Columns Usage

Shorthand helpers

Shorthand helpers are included as an alternative to common combinations of markup helpers:

Markup Shorthand 1

Markup Shorthand 2

Insert layout children: conditional and Spread

All layouts ignore null values in their children; this makes it possible to have conditional views depending on the value of an expression at page (re) build time.

The Spread helper allows to insert a variable number of children at a specific position in the children list (similar to what Flutter offers).

Markup Layout Insert Children Conditional Spread

Binding power

Thanks to the C# 10 CallerArgumentExpression attribute, you don't have to use strings or nameof() to specify binding paths with good performance. Instead you can use C# expressions and enjoy all the goodness that they bring: full intellisense, compiler checked, renaming support :
Markup Binding Expression

Note from the intellisense description in above image that the pathExpression parameter supports several convenience binding syntaxes, which allows to:

  • Identify the viewmodel part of the expression with parenthesis:
    path expression = viewmodel.path || (viewmodel expression).path, where path can contain . e.g.:
    • .Bind (vm.SelectedTweet) binds to "SelectedTweet"
    • .Bind ((vm.SelectedTweet).Title) binds to "Title"
    • .Bind ((vm.SelectedTweet).Author.Name) binds to "Author.Name"
  • Use ? with null-valued type instances to enjoy C# goodness without needing object instances e.g.:
    • .Bind (vm?.SelectedTweet?.Title) binds to "Title"
      Note that using ? can be necessary because the expression will be evaluated at runtime, even though we don't care about it's value; the CallerArgumentExpression attribute supplies an expression string in addition to the expression value.
  • You can still pass in string literals
    • .Bind ("SelectedTweet") binds to "SelectedTweet"

Any surrounding ", @ or whitespace characters in pathExpression are ignored

Bind supports almost all functionality that the UI framework offers for binding. In addition, there are many Bind overloads that allows to:

  • Omit the property name to bind to the default property of a view type:
    Bind Default Parameter
  • Bind with inline conversion:
    Bind Inline Conversion
  • Bind a command and it's parameter in one go:
    Bindcommand

Page anatomy - separate markup and UI logic

A typical markup page starts like this:

FlutterPage.cs:

using CSharpMarkup.<UI framework name>;
using static CSharpMarkup.<UI framework name>.Helpers;

namespace Examples;

partial class FlutterPage
{
    public void Build() => Content = 

Note the use of partial class; this lets you separate the UI markup from UI logic:

FlutterPage.logic.cs:

using <UI framework namespace>.Controls;

namespace Examples;

public sealed partial class FlutterPage : Page, IBuild
{
    readonly FlutterViewModel vm;

    public FlutterPage()
    {
        InitializeComponent(); // Only needed for WinUI
        DataContext = vm = <obtain viewmodel instance>;
        Build();

Namespace separation of markup and UI logic

IMPORTANT:

  • In C# markup files like <page>.cs:
    Include CSharpMarkup.* namespace usings but no UI objectmodel usings such as using Microsoft.UI.Xaml;

    (by design the type names in the CSharpMarkup namespace are identical to the type names in the UI objectmodel, so including both would cause ambiguities)

    Try to limit using the UI object model to UI logic files. If you must, you can use the UI objectmodel safely in C# markup files; a good practice then is to define global namespace using aliases, e.g. global using UI = Microsoft.UI;

    For more guidance, see the comments in the GlobalUsings.cs of a project created with dotnet new mcs-uno-markup2.

  • In UI logic files like <page>.logic.cs:
    Do not use CSharpMarkup objects

    Markup object instances are not safe to use outside of a markup expression (due to performance features - each markup object type has a single static instance to prevent allocating an extra object for each view). That is why Assign and Invoke (see below) pass the UI object contained in the markup object to the logic, instead of the markup object itself.

Integrate UI markup with UI logic

With Assign and Invoke you can integrate UI markup with UI logic:

SearchPage.cs:
Markup Logic Assign 1

SearchPage.logic.cs:
Markup Logic Assign 2

SearchPage.cs:
Markup Logic Invoke 1

SearchPage.logic.cs:
Markup Logic Invoke 2

Note:
In SearchPage.cs, StackPanel and TextBox are markup object types, while
in SearchPage.logic.cs they are the corresponding UI framework object types

Development workflow tips

Improve markup colorization in Visual Studio

There is no C# Markup IDE extension (yet...) to properly colorize markup, however C# Markup readability can be improved with this workaround in Visual Studio options:

Under Fonts and Colors, copy the color of User Types - Classes to User Members - Methods (with the Custom... button). Now the markup color for views and properties will no longer be the same.

Improve Markup Colors In Vs

csharpformarkup's People

Contributors

rdavisau avatar vincenth-net 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpformarkup's Issues

Need a recipe for adding/extending local Helpers to a project

For some reason, adding this to a client project breaks the current Helper class (haven't investigated deeply enough what other options are):

namespace CSharpMarkup.Wpf;

public static class Helpers
{
    public static TextBlock TextBlock(System.Windows.Documents.Inline[] chidren)
    {
        var ui = new System.Windows.Controls.TextBlock();
        foreach (var ch in chidren) ui.Inlines.Add(ch);

        return ui;
    }
}

Create TextBlock inlines helper

TextBlock can contain children (inlines), the current helper only allows a single Inline (which is the only option support by the WPF constructor).

The following is an example that isn't currently supported:

<TextBlock><Run Foreground="#FFCFD3DA" Text="Text1" /><Run FontWeight="Normal" Text="Text2" /></TextBlock>

Maybe something like:

public static TextBlock TextBlock(System.Windows.Documents.Inline[] chidren)
{
    var ui = new Windows.Controls.TextBlock();
    foreach (var ch in chidren)
    {
        ui.Inlines.Add(ch);
    }

    return ui;
}

Row()/Col() bug

Remove "if (row != 0)" and simmilar "return if default value" conditions from Row/Col/ColSpan/RowCol/etc. functions. It took me days to realize my code not working because of this. I remove and re-add views from one grid to other and change order. Some of views not changed from row X to 0. This conditions are totally unnecessary!

WPF DataTemplates not working

When I use this markup:

            ListView(() => 
                TextBlock("Item")
                .FontSize (30) .Foreground (Black)
            ) .Height (100) .Background (Yellow)
            .Bind(vm.Items)

And bind to a collection with three items, I can see three empty items of a few pixels high

When I set a breakpoint after var ui = new Windows.DataTemplate(xaml); here, the DataTemplate does not seem to have accepted the XAML - no children loaded.

I took over the XAML from the WinUI implementation.

Could you take a look @scottcg ?

Default Styles are not applied to controls (tested only on Label)

Default styles, such as:

<!--  This is the default style for all labels  -->
<Style TargetType="{x:Type Label}">
    <Setter Property="Foreground" Value="{DynamicResource FontColor}" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="Padding" Value="{DynamicResource LabelPadding}" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Setter Property="FontSize" Value="13" />
</Style>

Are not applied to Label() in markup.

In the c# code one can lookup the style and see that it is present using this:

var defaultStyle = App.Current.TryFindResource(typeof(System.Windows.Controls.Label)) as System.Windows.Style;

When manually applying this to the Label, it still doesn't work. That may mean there's something strange with how Label deals with Content during construction. Not sure.

You can see this in the Welcome_UI.cs code file.

Unity UI Toolkit support

I would love to use it with Unity's DOM-like UI Toolkit. This would be really helpful since game UI is pretty stuck in the stone age.

I was hoping there would be some kind of simple-ish interface I could implement to add support for an arbitrary UI Framework so I could do this. Any advice here?

app size?

I wonder if you have any idea or experience regarding how this effects app size. which one is better using c# or xaml or it wont even matter.

Thank you!

@VincentH-Net

First, thanks a million for taking the time to develop this. I wish it existed 5 years ago when I started learning Xamarin.Forms.

FWIW, I spent some time yesterday implementing this concept in UWP / Uno. This morning I used it on another project and was amazed at how much less painful it was to build and maintain the layouts.

Binding in UWP is now a joy!

THANK YOU!

ContentDialog is not parsed

screenshot

image

Steps to reproduce:

Add to example

FlutterPage.cs:

Button("Show ContentDialog").Command(A),

ContentDialog(
    StackPanel(TextBox(Text: "TextBox"))
)
.PrimaryButtonText("PrimaryText")
.Title("Title")
Assign(out contentDialog),

FlutterPage.logic.cs:

public FlutterPage()
{
    ...
    contentDialog.XamlRoot = App.Current.XamlRoot();
}

ContentDialog contentDialog;
ICommand aCommand;
public ICommand A => aCommand ??= new RelayCommandAsync(async () => await contentDialog.ShowAsync());

App.xaml.cs:

internal XamlRoot XamlRoot() => _window.Content.XamlRoot;

Another questions:

Is it possible to set object content through method call?

Something like:

ContentDialog(PrimaryButtonText: "abc", Title: "Title").Content(StackPanel(..))

instead of

ContentDialog(StackPanel(..)).PrimaryButtonText("abc").Title("Title")

What's about performance?

I should add to Treeview 10K elements sometimes. Is the performance impact near zero (in comparison with XAML)?
What performance scenarios do we need to be careful with?

Thank you for freeing us from XAML❤️

Support custom controls

What's about custom controls?

If the default controls generate by SourceGenerators, I suggest adding [Markup(typeof(MyControl))] that generates Markup's methods automatically. It seems to be possible to implement it.

Originally posted by @YegorStepanov in #19 (comment)

Support ControlTemplates

As discussed:

@VincentH-Net: ControlTemplates => Basically a reusable piece of C# Markup. Could be done by adding a factory helper that creates a control template from C# Markup content, similar to the layout factory helpers. Then you could use that helper in a local build method or in a derived control so it has a typesafe name

@scottcg: I don't see ControlTemplates

How to use RelativeLayout?

I need to use a RelativeLayout as a child of another screen element but I am struggling to see how I can do this in a declarative way, as the constraint is passed as a parameter to its Add() method.

Maybe a place for another helper, sort-of similar to the ones that allow enum names to be used for rows and columns in the Grid control?

Support for CollectionView

I'm trying to define a page with the markup and need a CollectionView, but can't work out how to define the ItemTemplate or ItemsLayout.

CollectionView isn't mentioned in any of your documentation and I can't find any matches for various searches I've done looking for examples or mentions.

I can go back to using XAML for the page, but I'd really prefer not to; for this old coder, defining things with pages of wordy untyped text that can easily disagree with itself just seems like going back to writing HTML in Notepad !!

Does this compile back to XAML in the background ?

Hi,

I have a question:
Does this compile back to XAML in the background ?

I currently already build my Xamarin.Forms UI's using code because of the terrible performance of using XAML it's self - so as long as this package doesn't compile back to XAML I would be very interested in trying it - especially to be able to move my only remaining XAML file left - which is for my Styles - to C#.

Thanks,

Matthew

Support WPF

Would be great to see the generators included in the source, maybe they are there and I'm just missing them.

I've been using similar hand-coded techniques for WPF (bunch of helper/extension classes) - but I don't want to maintain that any longer.

Thanks!

Missing helpers for some controls that have child(ren)

@scottcg wrote: I need some additional helpers for those controls that have a child/children (Border, Menu, MenuItem)

This is an issue in WinUI and WPF codegen; it should generate helpers for types that implement settable property public UIElement Child

Error when installing NUGET

Hello,

Install of https://www.nuget.org/packages/CSharpMarkup.WinUI/0.8.1-dev.6 on a VS 2022 project created with WinUI blank app templates fails and show:

Severity Code Description Project File Line Suppression State
Error Package restore failed. Rolling back package changes for 'WinUITrial'.
Error NU1605 Detected package downgrade: Microsoft.Windows.SDK.BuildTools from 10.0.22000.197 to 10.0.22000.194. Reference the package directly from the project to select a different version.
WinUITrial -> CSharpMarkup.WinUI 0.8.1-dev.6 -> Microsoft.Windows.SDK.BuildTools (>= 10.0.22000.197)
WinUITrial -> Microsoft.Windows.SDK.BuildTools (>= 10.0.22000.194) WinUITrial C:\Users\estra\source\repos\SerUI\WinUITrial\WinUITrial\WinUITrial.csproj 1

Thanks

Grid Definitions - Values for Stars?

Hi

I am really starting to love this library, and I can't wait for it to be part of Xamarin.Forms. Death to XAML :)

I can't figure out a way to provide a value to GridLength.Star when defining rows and columns. As far as I can tell I can either provide a numberic value, which is used as GridLength.Absolute, or I can provide a GridLength of .Star or .Auto... but I cannot give a numeric value AND a GridLength.

For example, if I want to create a grid with 3 columns, one of which is twice the size of the other two, I would do something like:

ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) });

Is there a snazzy way of doing this, like an overload that allows:

ColumnDefinitions = EnumsForGridRowsAndColumns.Columns.Define(
    (Cols.One, GridLength.Star, 1),
    (Cols.Two, GridLength.Star, 1),
    (ColsThree, GridLength.Star, 2));

Thanks!

Create additional Grid helper for Names/SharedSizeGroup

Consider adding an additional Grid helper to help when doing this:

<ColumnDefinitions>
  <ColumnDefinition x:Name="column1CloneForLayer0" SharedSizeGroup="column1" />
</ColumnDefinitions>

This also applies when referencing a size group and width:

<ColumnDefinitions>
  <ColumnDefinition Width="300" SharedSizeGroup="column1" />
</ColumnDefinitions>

MSBUILD : Custom warning : Injecting code into BindTap failed: Value cannot be null.

Hi there, I just started using your marvelous markup system and am most impressed, but I have come across a minor issue that I would appreciate some help with.

When I build my project including your XamarinFormsMarkupExtensions.cs I get the compiler warnings below;

1>MSBUILD : Custom warning : Injecting code into BindTap failed: Value cannot be null.
1>MSBUILD : Custom warning : Parameter name: method

It's not breaking anything, and commenting out the 3 BindTap interfaces from line 191 removes the warning but I thought you'd be interested to hear about it, I can't work out where the 'method' parameter it's talking about is so can't be of much help beyond this report.

I'm not using the interfaces at all, so I've left them commented out for now.

Add a Label Content property

Add a Label Content property helper to allow attaching text/string to a Label; Label as only a constructor at the monent

Label("label goes here")

To allow for this (currently this is an error):

Label()
    .Content("label goes here")

How do you nesting your files?

I have started using your extension as I mentioned before in my blog post here. Now, I'm looking for a file nesting extension for VS2019.

I would like to use the convention file.cs and file.logic.cs but all the extension I have installed did not work. DO you do it manually?

NuGet package

Hi,

Very interesting Idea about C sharp for Markup.

Do you consider to create a NuGet package?

Exception thrown in example

I am learning CSharpForMarkup; encountered issue with example WinUI when using WinUI library source instead of nuget packages.
Seems functional if I comment out the exception. Do not know things well enough to offer much at this point.
Attached Info
"Project" project setup
"Code" example code
"Exception" exception being thrown

Code
Exception
Project

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.