https://github.com/doomviruz/uiext.markup.wpf
WPF extensions library to define UI from code instead of XAML usage.
https://github.com/doomviruz/uiext.markup.wpf
csharp library markup wpf
Last synced: 10 months ago
JSON representation
WPF extensions library to define UI from code instead of XAML usage.
- Host: GitHub
- URL: https://github.com/doomviruz/uiext.markup.wpf
- Owner: doomviruz
- License: mit
- Created: 2020-07-29T06:39:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-26T08:17:04.000Z (over 5 years ago)
- Last Synced: 2025-07-29T04:24:50.845Z (11 months ago)
- Topics: csharp, library, markup, wpf
- Language: C#
- Homepage:
- Size: 203 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIExt.Markup.WPF
Draft WPF extensions library to define UI from code instead of XAML usage.
Inspired by VincentH-Net/CSharpForMarkup for Xamarin Forms.
## Nu-get
Nu-get package | Description
---------------|-------------
[UIExt.Markup.WPF](https://www.nuget.org/packages/UIExt.Markup.WPF) | Now 0.1.0 intial release published.
## Example
```csharp
public void Build() =>
this.Content(
Grid()
.RowDefs(RowDef.Height(72), RowDef.Height(30), RowDef.Height(385), RowDef.Height(80))
.Childs(
TextBlock()
.Foreground(SolidBrush("#ff000000"))
.Font(family: "SegoeUI", size: 20, style: FontStyles.Normal, weight: FontWeights.SemiBold)
.Text("SAMPLE DIALOG FOR UIExt.Markup.WPF")
.HAlignCenter()
.LineHeight(24)
.Row(0)
.Margin(24),
Grid()
.ColDefs(ColDef, ColDef)
.Row(1)
.Childs(
ToggleButton()
.Content("Toggle text visibility")
.Command(ViewModel.ToggleTextVisibilityCommand)
.Column(0),
TextBlock()
.Column(1)
.Foreground(Brushes.Red)
.VAlignCenter()
.HAlignCenter()
.Text("Some additional text")
.Bind(
VisibilityProperty,
Binding(nameof(ViewModel.AdditionalTextVisible), Converters.BoolToVisibilityConverter))),
TextBox()
.FocusStyleNone()
.Margin(24, 0, 24, 0)
.Border(1)
.BorderBrush(Black)
.Wrap()
.Row(2)
.Font("SegoeUI")
.FontSize(14)
.ReadOnly()
.Text("SOme text")
.VScrollAuto()
.HScrollAuto(),
Grid()
.Row(3)
.ColDefs(ColDef, ColDef)
.Childs(
Button()
.Content("ACTION")
.Name("ActionButton")
.Style(_accentDialogButtonStyle)
.Height(32)
.Width(145)
.HAlignRight()
.Column(0)
.Margin(24, 24, 3, 24)
.Command(ViewModel.ActionCommand),
Button()
.Content("EXIT")
.Name("ExitButton")
.Style(_dialogButtonStyle)
.Height(32)
.Width(145)
.HAlignLeft()
.Column(1)
.Margin(3, 24, 24, 24)
.Command(ViewModel.ExitCommand))));
```
---
## Control template definition example
```csharp
ControlTemplate DialogButtonTemplate = new ControlTemplate
{
TargetType = typeof(Button),
VisualTree =
BorderElement()
.Background(new TemplateBindingExtension(BackgroundProperty))
.BorderThickness(new TemplateBindingExtension(BorderThicknessProperty))
.BorderBrush(new TemplateBindingExtension(BorderBrushProperty))
.Childs(
BorderElement()
.Childs(
ContentPresenter()
.SetPropValue(HorizontalAlignmentProperty, HorizontalAlignment.Center)
.SetPropValue(VerticalAlignmentProperty, VerticalAlignment.Center)))
.Factory
};
```
---
## Style definition example
```csharp
Style DialogButtonStyle =
Style()
.Setters(
SnapsToPixels(true),
FontSize(14),
FontFamily("SegoeUI"),
FontWeight(FontWeights.Normal),
FontStyle(FontStyles.Normal),
Foreground(_buttonForegroundBrush),
BorderThickness(2),
BorderBrush(_buttonBorderBrush),
Background(_buttonBorderBrush),
Template(DialogButtonTemplate))
.Triggers(_mouseOverTrigger, _pressedTrigger);
```
---
## Simple converter example
```csharp
public class BoolToVisibilityConverter : ConverterBase
{
public override Visibility Convert(bool value, CultureInfo culture) => value ? Visibility.Visible : Visibility.Hidden;
public override bool ConvertBack(Visibility value, CultureInfo culture) => value == Visibility.Visible;
}
```
---
## Simple FP-style converter example
```csharp
FunctionalConverter InvertBoolToVisibilityConverter =
new FunctionalConverter(
convert: (value, culture) => value ? Visibility.Hidden : Visibility.Visible,
convertBack: (value, culture) => value != Visibility.Visible);
```
---