Brave 1.0.0

dotnet add package Brave --version 1.0.0
                    
NuGet\Install-Package Brave -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Brave" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Brave" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Brave" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Brave --version 1.0.0
                    
#r "nuget: Brave, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Brave@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Brave&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Brave&version=1.0.0
                    
Install as a Cake Tool

Brave

If it's possible and easy to do in XAML - do it in XAML.

Brave is a tiny library that uses a ResourceDictionary as a state holder and adds a small expression language for simple UI logic. It is not an MVVM framework and not a general-purpose state-management solution. Brave is meant for small UI state and simple interactions, written directly in XAML.

What Brave is

  • A lightweight way to store UI state in resources (e.g. $IsLoading, $Counter, $ErrorText)
  • A compact expression language for small UI actions and derived values
  • A good fit for:
    • visibility / enable-disable toggles
    • simple counters and flags
    • UI-only state (loading, error, selected item key, etc.)
    • small computed values for display

What Brave is not

  • Not a replacement for Bindings, ReactiveUI, MVVM, or proper domain/business logic
  • Not intended for complex logic or large apps where state should be structured and testable outside the view

Installation

NuGet:

dotnet add package Brave

How it works (high level)

  • brave:InitResources executes once (during XAML load) and writes values directly into the resource dictionary.

  • brave:Execute executes a compiled instruction list on demand (e.g. Button.Command).

  • Resources can be consumed via:

    • DynamicResource (best for simple �take value by key� cases)
    • brave:RBinding (for computed expressions and convenient string/number proxying)

Usage

1) Counter example

<Window xmlns="https://github.com/avaloniaui"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:brave="http://github.com/2Xpro-pop/Brave"

		x:Class="Counter.MainWindow"
		Title="Counter">

	<Button Resources="{brave:InitResources '$Counter=20 * 5 ^ 17 - 3; $Text=\'Counter: \' + $Counter '}"
	        Command="{brave:Execute Expression='$Counter++; $Text=\'Counter:\' + $Counter'}">
		<TextBlock Text="{DynamicResource $Text}"/>
	</Button>

</Window>

2) Editing numbers and showing computed output with RBinding

If you store $A and $B as numbers, you often want a nice proxy for editing and computed UI text. Use brave:RBinding:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:brave="http://github.com/2Xpro-pop/Brave"
        x:Class="Adder.MainWindow"
        Title="Adder">

  <StackPanel Spacing="8"
              Resources="{brave:InitResources '$A = 2d; $B = 11d'}">

    <TextBox Text="{brave:RBinding $A}" />
    <TextBox Text="{brave:RBinding $B}" />

    <TextBlock Text="{brave:RBinding '$A + $B'}" />
  </StackPanel>

</Window>

More examples: Sample Gallery (live demo) and Samples folder in the repository.

Expression language (supported operations)

Brave expressions are intentionally small and focused.

Literals

  • Numbers (decimal / hex / binary) with suffixes: 1, 1d, 1f, 1m, 0xFF, 0b1010
  • Strings: 'text', "text", verbatim: @"text", @'text'
  • Booleans: true, false
  • null

Variables / special values

  • Resource variables: $MyKey
  • $parameter - command parameter
  • $self - owner object (control instance)

Assignment

  • $A = 10
  • Multiple statements: $A = 1; $B = $A + 2
  • Compound: $A += 1, $A -= 2, $A *= 3, $A /= 4
  • Null-coalescing assignment: $A ??= 'default'

Indexing

  • Read: $List[0], $Dict[$Key]
  • Write: $List[0] = 42
  • Compound index assignment: $List[0] += 1

Invocation

  • $Action() - invoke a resource as a command
  • $Action($param) - invoke with a parameter expression

Arithmetic

  • + - * /
  • Unary negate: -value

Comparison

  • == != < <= > >=

Logical

  • !value
  • && and || with short-circuit via jumps

Null-coalescing and ternary

  • a ?? b
  • cond ? then : else

Bitwise

  • ~
  • & | ^

Increment / decrement

  • ++$A, $A++
  • --$A, $A--

Notes

  • Brave is designed for UI logic. Keep business logic outside XAML.
  • The runtime stack is intentionally small and pooled to reduce allocations.
  • Expressions are compiled into a high-level instruction list (cached), while resource tables are per-instance.

Roadmap / TODO

  • Binding to ViewModel properties
  • Dot-access for nested objects ($Hello.$World)
  • Binding to ObservableCollection
  • Binding to IObservable
  • Improve resource change notification performance
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Brave:

Package Downloads
Brave

A tiny library that uses a ResourceDictionary as a state holder and adds a small expression language for simple UI logic in XAML.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 92 2/14/2026