Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSM Docs #1996

Merged
merged 32 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dff7e9b
docs: adding markup reference docs
dansiegel Nov 2, 2022
941016c
chore: providing additional context for markup docs
dansiegel Dec 14, 2022
981b6f7
chore: add reference links to pre-generated packages
dansiegel Jan 17, 2023
29a8979
chore: updating docs for creating resources
dansiegel Jan 18, 2023
4b12b2f
fix: binding examples
dansiegel Mar 1, 2023
738335a
chore: update Styles doc
dansiegel Mar 21, 2023
51b3f22
chore: update docs
dansiegel May 2, 2023
902fc64
chore: add new HowTo
rafael-rosa-knowcode Jul 5, 2023
a64f9e3
chore: Add Step by Step, comparing Markup and XAML
rafael-rosa-knowcode Jul 10, 2023
a649ab5
chore: add image
rafael-rosa-knowcode Jul 10, 2023
c526ba4
chore: add new page
rafael-rosa-knowcode Jul 11, 2023
8004b6b
chore: add Toolkit
rafael-rosa-knowcode Jul 12, 2023
4b0e3dd
chore: add Theme
rafael-rosa-knowcode Jul 12, 2023
580618e
chore: add visualStates
rafael-rosa-knowcode Jul 13, 2023
aae24ab
chore: update theme and add Toggle Mode
rafael-rosa-knowcode Jul 14, 2023
8add091
chore: add Converters page
rafael-rosa-knowcode Jul 14, 2023
8c186da
chore: add MVUX
rafael-rosa-knowcode Jul 14, 2023
e884787
chore: move Markup Tutorials to the docs Tutorials area
dansiegel Oct 30, 2023
d98a452
chore: updating generator docs
dansiegel Oct 30, 2023
3e13341
chore: add reference to Themes Markup package
dansiegel Oct 30, 2023
2910699
chore: fixing spaces
dansiegel Oct 30, 2023
7faac40
chore: adding sections to AttachedProperty docs
dansiegel Oct 30, 2023
ca86499
chore: basic revisions
dansiegel Oct 30, 2023
92b0c69
docs: Use DataTemplate
pictos Oct 27, 2023
c883c16
docs: rebase + code review
pictos Oct 30, 2023
5d81907
docs: Add ViewModel and implement search functionality
pictos Oct 31, 2023
e4583f4
chore: updating getting started docs for markup
dansiegel Oct 31, 2023
bafb8e3
Update doc/Learn/Tutorials/Markup/HowTo-MarkupProject.md
nickrandolph Oct 31, 2023
19b36f9
docs: updated docs text
pictos Oct 31, 2023
dbca521
chore: update tutorial text
dansiegel Nov 1, 2023
f17c5c4
chore: Jerome's review requested changes
dansiegel Nov 1, 2023
3ecd06e
chore: Apply code review changes
jeromelaban Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 487 additions & 0 deletions doc/Learn/Tutorials/Markup/HowTo-CreateMarkupProject.md

Large diffs are not rendered by default.

220 changes: 220 additions & 0 deletions doc/Learn/Tutorials/Markup/HowTo-CustomMarkupProject-MVUX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
---
uid: Learn.Tutorials.HowToCustomMarkupProjectMVUX
---

# How to set up your own C# Markup project using MVUX

You can use this tutorial to learn how to set up a Uno Platform project using MVUX.

Create a new project using MVUX

- In this tutorial, you will [set up the environment and create the Markup project and MVUX](xref:Learn.Tutorials.HowToMarkupMVUX)

## Start With MVUX.

The MVUX provides a structured approach to managing the application state and updating the user interface within the Uno Platform, following the principles of MVU architecture.
It aims to simplify state management and UI development by providing abstractions and conventions for working with feeds, states, and views.

In this tutorial, you can learn about the [MVUX](xref:Overview.Mvux.Overview) using XAML.

The same concept can be applied to C# Markup.

By the way, let's use the same existing example in XAML to make the conversation in C# Markup.
Let's try to simplify the use to be able to explain the features.

**WeatherApp Sample XAML**

You can find the code for our weather app here: https://github.com/unoplatform/Uno.Samples/tree/master/UI/MvuxHowTos/WeatherApp



### Add elements and set attributes on the UI.

Change the *MainPage* to have a different content as the sample bellow.

- Customizing the UI

# [**C# Markup**](#tab/cs)

#### C# Markup.

- The code below shows how to use the FeedView to list information on MVUX.
But first to have the information we will create the WeatherModel and the WeatherService.

First, let's create the Weather Service.
Create a class file named `WeatherService.cs` and add the content below to the file.
In this File we will create a record WeatherInfo with contains the attribute Temperature.
After that, we create an IWeatherService, (With defining the GetCurrentWeather) and an implementation of it on the WeatherService.
For this case, just have a new WeatherInfo with a random temperature.

> Notice that the WeatherInfo is been created for every new request, following the MVU standard.

```csharp
namespace MySampleProjectMVUX;

public partial record WeatherInfo(int Temperature);

public interface IWeatherService
{
ValueTask<WeatherInfo> GetCurrentWeather(CancellationToken ct);
}

public class WeatherService : IWeatherService
{
public async ValueTask<WeatherInfo> GetCurrentWeather(CancellationToken ct)
{
await Task.Delay(TimeSpan.FromSeconds(1), ct);
return new WeatherInfo(new Random().Next(-40, 40));
}
}
```

Next, let's create the Model.
Create a class file named `WeatherModel.cs` and add the content below to the file.
In this case, we are creating a `WeatherModel` which contains an `IFeed` of the `WeatherInfo`.

```csharp
namespace MySampleProjectMVUX;

using Uno.Extensions.Reactive;

public partial record WeatherModel(IWeatherService WeatherService)
{
public IFeed<WeatherInfo> CurrentWeather => Feed.Async(WeatherService.GetCurrentWeather);
}
```

And now we need to add the DataContext to the Page.

> Notice that we are using the class BindableWeatherModel auto generated by the MVUX.

```csharp
this.DataContext = new BindableWeatherModel(new WeatherService());

this.DataContext<BindableWeatherModel>((page, vm) => page
);

```

And after that add the FeedView.


```csharp
new FeedView()
.Source(() => vm.CurrentWeather)
//.Source(x => x.Bind(() => vm.CurrentWeather))
dansiegel marked this conversation as resolved.
Show resolved Hide resolved

//You can use the Function
.DataTemplate((sample) => GetDataTemplate())

//Or you can use direct the Element
.ProgressTemplate<StackPanel>((sample) =>
new StackPanel().Children(
new TextBlock().Text("Loading...")
)
)
```

# [**XAML**](#tab/cli)

#### XAML

MainPage.xaml

```xml
<mvux:FeedView Source="{Binding CurrentWeather}">
<DataTemplate>
<StackPanel>
<TextBlock DataContext="{Binding Data}" Text="{Binding Temperature}" />
<Button Content="Refresh" Command="{Binding Refresh}" />
</StackPanel>
</DataTemplate>
<mvux:FeedView.ProgressTemplate>
<DataTemplate>
<TextBlock Text="Requesting temperature..."/>
</DataTemplate>
</mvux:FeedView.ProgressTemplate>
</mvux:FeedView>
```

MainPage.xaml.cs

```csharp
public MainPage()
{
this.InitializeComponent();

this.DataContext = new BindableWeatherModel(new WeatherService());
}
```
# [**Full Code**](#tab/code)

#### Full C# Markup code

- Example of the complete code on the MainPage.cs, so you can follow along in your own project.

```csharp
namespace MySampleProjectMVUX;
using Uno.Extensions.Reactive.UI;

public sealed partial class MainPage : Page
{
public MainPage()
{

this.DataContext = new BindableWeatherModel(new WeatherService());

this.DataContext<BindableWeatherModel>((page, vm) => page
.Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
.Content(
new StackPanel()
.VerticalAlignment(VerticalAlignment.Center)
.HorizontalAlignment(HorizontalAlignment.Center)
.Children(
new TextBlock()
.Text("Hello Uno Platform!"),
new FeedView()
.Source(() => vm.CurrentWeather)
.Source(x => x.Bind(() => vm.CurrentWeather))

//You can use the Function
.DataTemplate((sample) => GetDataTemplate())

//Or you can use direct the Element
.ProgressTemplate<StackPanel>((sample) =>
new StackPanel().Children(
new TextBlock().Text("Loading...")
)
)
)
)
);
}
//Using Template
public StackPanel GetDataTemplate()
{
return new StackPanel()
.Orientation(Orientation.Vertical)
.Children(
new TextBlock()
.Margin(10)
//.DataContext(x => x.Bind("Data"))
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
//.Text(x => x.Bind("Temperature"))
.Text("Temperature")
//,
//new Button()
// .Margin(10)
// .Content("Refresh")
// .Command(x => x.Bind("Refresh"))
);
}
}

```

## Next Steps

- [Custom your own C# Markup - Learn how to change Visual States and User Controls](xref:Learn.Tutorials.HowToCustomMarkupProjectVisualStates)
- [Custom your own C# Markup - Learn how to use Toolkit](xref:Learn.Tutorials.HowToCustomMarkupProjectToolkit)
- [Custom your own C# Markup - Learn how to Change the Theme](xref:Learn.Tutorials.HowToCustomMarkupProjectTheme)
- [Custom your own C# Markup - Learn how to use MVUX](xref:Learn.Tutorials.HowToCustomMarkupProjectMVUX)
Loading