[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M756H1FCAZ93D1BWFYDPC279":3,"skill-same:01M756H1FCAZ93D1BWFYDPC279":51},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M756H1FCAZ93D1BWFYDPC279","maui-data-binding",null,"Guidance for .NET MAUI XAML and C# data bindings — compiled bindings, INotifyPropertyChanged \u002F ObservableObject, value converters, binding modes, multi-binding, relative bindings, fallbacks, and MVVM best practices. USE FOR: setting up compiled bindings with x:DataType, implementing INotifyPropertyChanged or CommunityToolkit ObservableObject, creating IValueConverter \u002F IMultiValueConverter, choosing binding modes, configuring BindingContext, relative bindings, binding fallbacks, StringFormat, code-behind SetBinding with lambdas, and enforcing XC0022\u002FXC0025 warnings. DO NOT USE FOR: CollectionView item templates and layouts (use maui-collectionview), Shell navigation data passing (use maui-shell-navigation), dependency injection (use maui-dependency-injection), or animations triggered by property changes (use .NET MAUI animation APIs).","weiflycc-cmd\u002Fskills","weiflycc-cmd","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F250846518?v=4","01M756C4PFGZJWKK04WFB9S5XF","威飛工作室","01M756C4QJJ66QDXN2RN6SXY87",0,"MIT","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-maui\u002Fskills\u002Fmaui-data-binding\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: maui-data-binding\ndescription: >-\n  Guidance for .NET MAUI XAML and C# data bindings — compiled bindings,\n  INotifyPropertyChanged \u002F ObservableObject, value converters, binding modes,\n  multi-binding, relative bindings, fallbacks, and MVVM best practices.\n  USE FOR: setting up compiled bindings with x:DataType, implementing\n  INotifyPropertyChanged or CommunityToolkit ObservableObject, creating\n  IValueConverter \u002F IMultiValueConverter, choosing binding modes, configuring\n  BindingContext, relative bindings, binding fallbacks, StringFormat,\n  code-behind SetBinding with lambdas, and enforcing XC0022\u002FXC0025 warnings.\n  DO NOT USE FOR: CollectionView item templates and layouts (use\n  maui-collectionview), Shell navigation data passing (use\n  maui-shell-navigation), dependency injection (use maui-dependency-injection),\n  or animations triggered by property changes (use .NET MAUI animation APIs).\nlicense: MIT\n---\n\n# .NET MAUI Data Binding\n\nWire UI controls to ViewModel properties with compile-time safety, correct\nchange notification, and minimal overhead. Prefer compiled bindings everywhere\nand treat binding warnings as build errors.\n\n## When to Use\n\n- Adding `x:DataType` compiled bindings to a new or existing page\n- Implementing `INotifyPropertyChanged` or CommunityToolkit `ObservableObject`\n- Creating or consuming `IValueConverter` \u002F `IMultiValueConverter`\n- Choosing the correct `BindingMode` for a control property\n- Setting `BindingContext` in XAML or code-behind\n- Using relative bindings (`Self`, `AncestorType`, `TemplatedParent`)\n- Applying `StringFormat`, `FallbackValue`, or `TargetNullValue`\n- Writing AOT-safe code bindings with `SetBinding` and lambdas (.NET 9+)\n\n## When Not to Use\n\n- **CollectionView layouts \u002F templates** — use the `maui-collectionview` skill\n- **Shell navigation parameters** — use the `maui-shell-navigation` skill\n- **Service registration \u002F DI** — use the `maui-dependency-injection` skill\n- **Property-change-triggered animations** — use built-in [.NET MAUI animation APIs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Fuser-interface\u002Fanimation\u002Fbasic)\n\n## Inputs\n\n- A .NET MAUI project targeting .NET 8 or later\n- XAML pages or C# code-behind where bindings are declared\n- A ViewModel class (or plan to create one)\n\n---\n\n## Compiled Bindings — x:DataType Placement\n\nCompiled bindings are **8–20× faster** than reflection-based bindings and are\nrequired for NativeAOT \u002F trimming. Enable them with `x:DataType`.\n\n### Placement rules\n\nSet `x:DataType` **only where `BindingContext` is set**:\n\n1. **Page \u002F View root** — where you assign `BindingContext`.\n2. **DataTemplate** — which creates a new binding scope.\n\nDo **not** scatter `x:DataType` on arbitrary child elements. Adding\n`x:DataType=\"x:Object\"` on children to escape compiled bindings is an\nanti-pattern — it disables compile-time checking and reintroduces reflection.\n\n```xml\n\u003C!-- ✅ Correct: x:DataType at the page root -->\n\u003CContentPage xmlns:vm=\"clr-namespace:MyApp.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">\n    \u003CStackLayout>\n        \u003CLabel Text=\"{Binding Title}\" \u002F>\n        \u003CSlider Value=\"{Binding Progress}\" \u002F>\n    \u003C\u002FStackLayout>\n\u003C\u002FContentPage>\n\n\u003C!-- ❌ Wrong: x:DataType scattered on children -->\n\u003CContentPage x:DataType=\"vm:MainViewModel\">\n    \u003CStackLayout>\n        \u003CLabel Text=\"{Binding Title}\" \u002F>\n        \u003CSlider x:DataType=\"x:Object\" Value=\"{Binding Progress}\" \u002F>\n    \u003C\u002FStackLayout>\n\u003C\u002FContentPage>\n```\n\n### DataTemplate always needs its own x:DataType\n\n```xml\n\u003CCollectionView ItemsSource=\"{Binding People}\">\n    \u003CCollectionView.ItemTemplate>\n        \u003CDataTemplate x:DataType=\"model:Person\">\n            \u003CLabel Text=\"{Binding FullName}\" \u002F>\n        \u003C\u002FDataTemplate>\n    \u003C\u002FCollectionView.ItemTemplate>\n\u003C\u002FCollectionView>\n```\n\n### Enforce binding warnings as errors\n\n| Warning | Meaning |\n|---------|---------|\n| **XC0022** | Binding path not found on the declared `x:DataType` |\n| **XC0023** | Property is not bindable |\n| **XC0024** | `x:DataType` type not found |\n| **XC0025** | Binding used without `x:DataType` (non-compiled fallback) |\n\nAdd to the `.csproj`:\n\n```xml\n\u003CWarningsAsErrors>XC0022;XC0025\u003C\u002FWarningsAsErrors>\n```\n\n---\n\n## Binding Modes\n\nSet `Mode` explicitly **only** when overriding the default. Most properties\nalready have the correct default:\n\n| Mode | Direction | Use case |\n|------|-----------|----------|\n| `OneWay` | Source → Target | Display-only (default for most properties) |\n| `TwoWay` | Source ↔ Target | Editable controls (`Entry.Text`, `Switch.IsToggled`) |\n| `OneWayToSource` | Target → Source | Read user input without pushing back to UI |\n| `OneTime` | Source → Target (once) | Static values; no change-tracking overhead |\n\n```xml\n\u003C!-- ✅ Defaults — omit Mode -->\n\u003CLabel Text=\"{Binding Score}\" \u002F>\n\u003CEntry Text=\"{Binding UserName}\" \u002F>\n\u003CSwitch IsToggled=\"{Binding DarkMode}\" \u002F>\n\n\u003C!-- ✅ Override only when needed -->\n\u003CLabel Text=\"{Binding Title, Mode=OneTime}\" \u002F>\n\u003CEntry Text=\"{Binding SearchQuery, Mode=OneWayToSource}\" \u002F>\n\n\u003C!-- ❌ Redundant — adds noise -->\n\u003CLabel Text=\"{Binding Score, Mode=OneWay}\" \u002F>\n\u003CEntry Text=\"{Binding UserName, Mode=TwoWay}\" \u002F>\n```\n\n---\n\n## BindingContext and Property Paths\n\nEvery `BindableObject` inherits `BindingContext` from its parent unless\nexplicitly set. Property paths support dot notation and indexers:\n\n```xml\n\u003CLabel Text=\"{Binding Address.City}\" \u002F>\n\u003CLabel Text=\"{Binding Items[0].Name}\" \u002F>\n```\n\nSet `BindingContext` in XAML:\n\n```xml\n\u003CContentPage xmlns:vm=\"clr-namespace:MyApp.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">\n    \u003CContentPage.BindingContext>\n        \u003Cvm:MainViewModel \u002F>\n    \u003C\u002FContentPage.BindingContext>\n\u003C\u002FContentPage>\n```\n\nOr in code-behind (preferred with DI):\n\n```csharp\npublic MainPage(MainViewModel vm)\n{\n    InitializeComponent();\n    BindingContext = vm;\n}\n```\n\n---\n\n## INotifyPropertyChanged and ObservableObject\n\n### Manual implementation\n\n```csharp\npublic class MainViewModel : INotifyPropertyChanged\n{\n    public event PropertyChangedEventHandler? PropertyChanged;\n\n    private string _title = string.Empty;\n    public string Title\n    {\n        get => _title;\n        set\n        {\n            if (_title != value)\n            {\n                _title = value;\n                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title)));\n            }\n        }\n    }\n}\n```\n\n### CommunityToolkit.Mvvm (recommended)\n\n```csharp\nusing CommunityToolkit.Mvvm.ComponentModel;\nusing CommunityToolkit.Mvvm.Input;\n\npublic partial class MainViewModel : ObservableObject\n{\n    [ObservableProperty]\n    private string _title = string.Empty;\n\n    [RelayCommand]\n    private async Task LoadDataAsync() { \u002F* ... *\u002F }\n}\n```\n\nThe source generator creates the `Title` property, `PropertyChanged` raise,\nand `LoadDataCommand` automatically.\n\n---\n\n## Value Converters — IValueConverter\n\nImplement `Convert` (source → target) and `ConvertBack` (target → source):\n\n```csharp\npublic class IntToBoolConverter : IValueConverter\n{\n    public object? Convert(object? value, Type targetType,\n        object? parameter, CultureInfo culture)\n        => value is int i && i != 0;\n\n    public object? ConvertBack(object? value, Type targetType,\n        object? parameter, CultureInfo culture)\n        => value is true ? 1 : 0;\n}\n```\n\nDeclare in XAML resources and consume:\n\n```xml\n\u003CContentPage.Resources>\n    \u003Clocal:IntToBoolConverter x:Key=\"IntToBool\" \u002F>\n\u003C\u002FContentPage.Resources>\n\n\u003CSwitch IsToggled=\"{Binding Count, Converter={StaticResource IntToBool}}\" \u002F>\n```\n\n`ConverterParameter` is always passed as a **string** — parse inside `Convert`:\n\n```xml\n\u003CLabel Text=\"{Binding Score, Converter={StaticResource ThresholdConverter},\n              ConverterParameter=50}\" \u002F>\n```\n\n---\n\n## Multi-Binding\n\nCombine multiple source values with `IMultiValueConverter`:\n\n```xml\n\u003CLabel>\n    \u003CLabel.Text>\n        \u003CMultiBinding Converter=\"{StaticResource FullNameConverter}\">\n            \u003CBinding Path=\"FirstName\" \u002F>\n            \u003CBinding Path=\"LastName\" \u002F>\n        \u003C\u002FMultiBinding>\n    \u003C\u002FLabel.Text>\n\u003C\u002FLabel>\n```\n\n```csharp\npublic class FullNameConverter : IMultiValueConverter\n{\n    public object Convert(object[] values, Type targetType,\n        object parameter, CultureInfo culture)\n    {\n        if (values.Length == 2 && values[0] is string first\n            && values[1] is string last)\n            return $\"{first} {last}\";\n        return string.Empty;\n    }\n\n    public object[] ConvertBack(object value, Type[] targetTypes,\n        object parameter, CultureInfo culture)\n        => throw new NotSupportedException();\n}\n```\n\n---\n\n## Relative Bindings\n\n| Source | Syntax | Use case |\n|--------|--------|----------|\n| Self | `{Binding Source={RelativeSource Self}, Path=WidthRequest}` | Bind to own properties |\n| Ancestor | `{Binding BindingContext.Title, Source={RelativeSource AncestorType={x:Type ContentPage}}}` | Reach parent BindingContext |\n| TemplatedParent | `{Binding Source={RelativeSource TemplatedParent}, Path=Padding}` | Inside ControlTemplate |\n\n```xml\n\u003C!-- Square box: Height = Width -->\n\u003CBoxView WidthRequest=\"100\"\n         HeightRequest=\"{Binding Source={RelativeSource Self}, Path=WidthRequest}\" \u002F>\n```\n\n---\n\n## StringFormat\n\nUse `Binding.StringFormat` for simple display formatting without a converter:\n\n```xml\n\u003CLabel Text=\"{Binding Price, StringFormat='Total: {0:C2}'}\" \u002F>\n\u003CLabel Text=\"{Binding DueDate, StringFormat='{0:MMM dd, yyyy}'}\" \u002F>\n```\n\nWrap the format string in single quotes when it contains commas or braces.\n\n---\n\n## Binding Fallbacks\n\n- **FallbackValue** — used when the binding path cannot be resolved or the\n  converter throws.\n- **TargetNullValue** — used when the bound value is `null`.\n\n```xml\n\u003CLabel Text=\"{Binding MiddleName, TargetNullValue='(none)',\n              FallbackValue='unavailable'}\" \u002F>\n\u003CImage Source=\"{Binding AvatarUrl, TargetNullValue='default_avatar.png'}\" \u002F>\n```\n\n---\n\n## .NET 9+ Code Bindings (AOT-safe)\n\nFully AOT-safe, no reflection:\n\n```csharp\nlabel.SetBinding(Label.TextProperty,\n    static (PersonViewModel vm) => vm.FullName);\n\nentry.SetBinding(Entry.TextProperty,\n    static (PersonViewModel vm) => vm.Age,\n    mode: BindingMode.TwoWay,\n    converter: new IntToStringConverter());\n```\n\n---\n\n## Threading\n\nMAUI automatically marshals `PropertyChanged` to the UI thread — you can raise\nit from any thread. **However**, direct `ObservableCollection` mutations\n(Add \u002F Remove) from background threads may crash:\n\n```csharp\n\u002F\u002F ✅ Safe — PropertyChanged is auto-marshalled\nawait Task.Run(() => Title = \"Loaded\");\n\n\u002F\u002F ⚠️ ObservableCollection.Add — dispatch to UI thread\nMainThread.BeginInvokeOnMainThread(() => Items.Add(newItem));\n```\n\n---\n\n## Common Pitfalls\n\n| Mistake | Fix |\n|---------|-----|\n| Missing `x:DataType` — bindings silently fall back to reflection | Add `x:DataType` at page root and every `DataTemplate`; enable `XC0025` as error |\n| Forgetting to set `BindingContext` | Set in XAML (`\u003CPage.BindingContext>`) or inject via constructor |\n| Specifying redundant `Mode=OneWay` \u002F `Mode=TwoWay` | Omit `Mode` when using the control's default |\n| ViewModel does not implement `INotifyPropertyChanged` | Use `ObservableObject` from CommunityToolkit.Mvvm or implement manually |\n| Mutating `ObservableCollection` off the UI thread | Wrap mutations in `MainThread.BeginInvokeOnMainThread` |\n| Complex converter chains in hot paths | Pre-compute values in the ViewModel instead |\n| Using `x:DataType=\"x:Object\"` to escape compiled bindings | Restructure bindings; keep compile-time safety |\n| Binding to non-public properties | Binding targets must be `public` properties (fields are ignored) |\n\n---\n\n## References\n\n- [Data binding overview](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002F)\n- [Compiled bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fcompiled-bindings)\n- [Value converters](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fconverters)\n- [Relative bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Frelative-bindings)\n- [Multi-bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fmultibindings)\n- [CommunityToolkit.Mvvm](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fcommunitytoolkit\u002Fmvvm\u002F)\n","# .NET MAUI Data Binding\n\nWire UI controls to ViewModel properties with compile-time safety, correct\nchange notification, and minimal overhead. Prefer compiled bindings everywhere\nand treat binding warnings as build errors.\n\n## When to Use\n\n- Adding `x:DataType` compiled bindings to a new or existing page\n- Implementing `INotifyPropertyChanged` or CommunityToolkit `ObservableObject`\n- Creating or consuming `IValueConverter` \u002F `IMultiValueConverter`\n- Choosing the correct `BindingMode` for a control property\n- Setting `BindingContext` in XAML or code-behind\n- Using relative bindings (`Self`, `AncestorType`, `TemplatedParent`)\n- Applying `StringFormat`, `FallbackValue`, or `TargetNullValue`\n- Writing AOT-safe code bindings with `SetBinding` and lambdas (.NET 9+)\n\n## When Not to Use\n\n- **CollectionView layouts \u002F templates** — use the `maui-collectionview` skill\n- **Shell navigation parameters** — use the `maui-shell-navigation` skill\n- **Service registration \u002F DI** — use the `maui-dependency-injection` skill\n- **Property-change-triggered animations** — use built-in [.NET MAUI animation APIs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Fuser-interface\u002Fanimation\u002Fbasic)\n\n## Inputs\n\n- A .NET MAUI project targeting .NET 8 or later\n- XAML pages or C# code-behind where bindings are declared\n- A ViewModel class (or plan to create one)\n\n---\n\n## Compiled Bindings — x:DataType Placement\n\nCompiled bindings are **8–20× faster** than reflection-based bindings and are\nrequired for NativeAOT \u002F trimming. Enable them with `x:DataType`.\n\n### Placement rules\n\nSet `x:DataType` **only where `BindingContext` is set**:\n\n1. **Page \u002F View root** — where you assign `BindingContext`.\n2. **DataTemplate** — which creates a new binding scope.\n\nDo **not** scatter `x:DataType` on arbitrary child elements. Adding\n`x:DataType=\"x:Object\"` on children to escape compiled bindings is an\nanti-pattern — it disables compile-time checking and reintroduces reflection.\n\n```xml\n\u003C!-- ✅ Correct: x:DataType at the page root -->\n\u003CContentPage xmlns:vm=\"clr-namespace:MyApp.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">\n    \u003CStackLayout>\n        \u003CLabel Text=\"{Binding Title}\" \u002F>\n        \u003CSlider Value=\"{Binding Progress}\" \u002F>\n    \u003C\u002FStackLayout>\n\u003C\u002FContentPage>\n\n\u003C!-- ❌ Wrong: x:DataType scattered on children -->\n\u003CContentPage x:DataType=\"vm:MainViewModel\">\n    \u003CStackLayout>\n        \u003CLabel Text=\"{Binding Title}\" \u002F>\n        \u003CSlider x:DataType=\"x:Object\" Value=\"{Binding Progress}\" \u002F>\n    \u003C\u002FStackLayout>\n\u003C\u002FContentPage>\n```\n\n### DataTemplate always needs its own x:DataType\n\n```xml\n\u003CCollectionView ItemsSource=\"{Binding People}\">\n    \u003CCollectionView.ItemTemplate>\n        \u003CDataTemplate x:DataType=\"model:Person\">\n            \u003CLabel Text=\"{Binding FullName}\" \u002F>\n        \u003C\u002FDataTemplate>\n    \u003C\u002FCollectionView.ItemTemplate>\n\u003C\u002FCollectionView>\n```\n\n### Enforce binding warnings as errors\n\n| Warning | Meaning |\n|---------|---------|\n| **XC0022** | Binding path not found on the declared `x:DataType` |\n| **XC0023** | Property is not bindable |\n| **XC0024** | `x:DataType` type not found |\n| **XC0025** | Binding used without `x:DataType` (non-compiled fallback) |\n\nAdd to the `.csproj`:\n\n```xml\n\u003CWarningsAsErrors>XC0022;XC0025\u003C\u002FWarningsAsErrors>\n```\n\n---\n\n## Binding Modes\n\nSet `Mode` explicitly **only** when overriding the default. Most properties\nalready have the correct default:\n\n| Mode | Direction | Use case |\n|------|-----------|----------|\n| `OneWay` | Source → Target | Display-only (default for most properties) |\n| `TwoWay` | Source ↔ Target | Editable controls (`Entry.Text`, `Switch.IsToggled`) |\n| `OneWayToSource` | Target → Source | Read user input without pushing back to UI |\n| `OneTime` | Source → Target (once) | Static values; no change-tracking overhead |\n\n```xml\n\u003C!-- ✅ Defaults — omit Mode -->\n\u003CLabel Text=\"{Binding Score}\" \u002F>\n\u003CEntry Text=\"{Binding UserName}\" \u002F>\n\u003CSwitch IsToggled=\"{Binding DarkMode}\" \u002F>\n\n\u003C!-- ✅ Override only when needed -->\n\u003CLabel Text=\"{Binding Title, Mode=OneTime}\" \u002F>\n\u003CEntry Text=\"{Binding SearchQuery, Mode=OneWayToSource}\" \u002F>\n\n\u003C!-- ❌ Redundant — adds noise -->\n\u003CLabel Text=\"{Binding Score, Mode=OneWay}\" \u002F>\n\u003CEntry Text=\"{Binding UserName, Mode=TwoWay}\" \u002F>\n```\n\n---\n\n## BindingContext and Property Paths\n\nEvery `BindableObject` inherits `BindingContext` from its parent unless\nexplicitly set. Property paths support dot notation and indexers:\n\n```xml\n\u003CLabel Text=\"{Binding Address.City}\" \u002F>\n\u003CLabel Text=\"{Binding Items[0].Name}\" \u002F>\n```\n\nSet `BindingContext` in XAML:\n\n```xml\n\u003CContentPage xmlns:vm=\"clr-namespace:MyApp.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">\n    \u003CContentPage.BindingContext>\n        \u003Cvm:MainViewModel \u002F>\n    \u003C\u002FContentPage.BindingContext>\n\u003C\u002FContentPage>\n```\n\nOr in code-behind (preferred with DI):\n\n```csharp\npublic MainPage(MainViewModel vm)\n{\n    InitializeComponent();\n    BindingContext = vm;\n}\n```\n\n---\n\n## INotifyPropertyChanged and ObservableObject\n\n### Manual implementation\n\n```csharp\npublic class MainViewModel : INotifyPropertyChanged\n{\n    public event PropertyChangedEventHandler? PropertyChanged;\n\n    private string _title = string.Empty;\n    public string Title\n    {\n        get => _title;\n        set\n        {\n            if (_title != value)\n            {\n                _title = value;\n                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title)));\n            }\n        }\n    }\n}\n```\n\n### CommunityToolkit.Mvvm (recommended)\n\n```csharp\nusing CommunityToolkit.Mvvm.ComponentModel;\nusing CommunityToolkit.Mvvm.Input;\n\npublic partial class MainViewModel : ObservableObject\n{\n    [ObservableProperty]\n    private string _title = string.Empty;\n\n    [RelayCommand]\n    private async Task LoadDataAsync() { \u002F* ... *\u002F }\n}\n```\n\nThe source generator creates the `Title` property, `PropertyChanged` raise,\nand `LoadDataCommand` automatically.\n\n---\n\n## Value Converters — IValueConverter\n\nImplement `Convert` (source → target) and `ConvertBack` (target → source):\n\n```csharp\npublic class IntToBoolConverter : IValueConverter\n{\n    public object? Convert(object? value, Type targetType,\n        object? parameter, CultureInfo culture)\n        => value is int i && i != 0;\n\n    public object? ConvertBack(object? value, Type targetType,\n        object? parameter, CultureInfo culture)\n        => value is true ? 1 : 0;\n}\n```\n\nDeclare in XAML resources and consume:\n\n```xml\n\u003CContentPage.Resources>\n    \u003Clocal:IntToBoolConverter x:Key=\"IntToBool\" \u002F>\n\u003C\u002FContentPage.Resources>\n\n\u003CSwitch IsToggled=\"{Binding Count, Converter={StaticResource IntToBool}}\" \u002F>\n```\n\n`ConverterParameter` is always passed as a **string** — parse inside `Convert`:\n\n```xml\n\u003CLabel Text=\"{Binding Score, Converter={StaticResource ThresholdConverter},\n              ConverterParameter=50}\" \u002F>\n```\n\n---\n\n## Multi-Binding\n\nCombine multiple source values with `IMultiValueConverter`:\n\n```xml\n\u003CLabel>\n    \u003CLabel.Text>\n        \u003CMultiBinding Converter=\"{StaticResource FullNameConverter}\">\n            \u003CBinding Path=\"FirstName\" \u002F>\n            \u003CBinding Path=\"LastName\" \u002F>\n        \u003C\u002FMultiBinding>\n    \u003C\u002FLabel.Text>\n\u003C\u002FLabel>\n```\n\n```csharp\npublic class FullNameConverter : IMultiValueConverter\n{\n    public object Convert(object[] values, Type targetType,\n        object parameter, CultureInfo culture)\n    {\n        if (values.Length == 2 && values[0] is string first\n            && values[1] is string last)\n            return $\"{first} {last}\";\n        return string.Empty;\n    }\n\n    public object[] ConvertBack(object value, Type[] targetTypes,\n        object parameter, CultureInfo culture)\n        => throw new NotSupportedException();\n}\n```\n\n---\n\n## Relative Bindings\n\n| Source | Syntax | Use case |\n|--------|--------|----------|\n| Self | `{Binding Source={RelativeSource Self}, Path=WidthRequest}` | Bind to own properties |\n| Ancestor | `{Binding BindingContext.Title, Source={RelativeSource AncestorType={x:Type ContentPage}}}` | Reach parent BindingContext |\n| TemplatedParent | `{Binding Source={RelativeSource TemplatedParent}, Path=Padding}` | Inside ControlTemplate |\n\n```xml\n\u003C!-- Square box: Height = Width -->\n\u003CBoxView WidthRequest=\"100\"\n         HeightRequest=\"{Binding Source={RelativeSource Self}, Path=WidthRequest}\" \u002F>\n```\n\n---\n\n## StringFormat\n\nUse `Binding.StringFormat` for simple display formatting without a converter:\n\n```xml\n\u003CLabel Text=\"{Binding Price, StringFormat='Total: {0:C2}'}\" \u002F>\n\u003CLabel Text=\"{Binding DueDate, StringFormat='{0:MMM dd, yyyy}'}\" \u002F>\n```\n\nWrap the format string in single quotes when it contains commas or braces.\n\n---\n\n## Binding Fallbacks\n\n- **FallbackValue** — used when the binding path cannot be resolved or the\n  converter throws.\n- **TargetNullValue** — used when the bound value is `null`.\n\n```xml\n\u003CLabel Text=\"{Binding MiddleName, TargetNullValue='(none)',\n              FallbackValue='unavailable'}\" \u002F>\n\u003CImage Source=\"{Binding AvatarUrl, TargetNullValue='default_avatar.png'}\" \u002F>\n```\n\n---\n\n## .NET 9+ Code Bindings (AOT-safe)\n\nFully AOT-safe, no reflection:\n\n```csharp\nlabel.SetBinding(Label.TextProperty,\n    static (PersonViewModel vm) => vm.FullName);\n\nentry.SetBinding(Entry.TextProperty,\n    static (PersonViewModel vm) => vm.Age,\n    mode: BindingMode.TwoWay,\n    converter: new IntToStringConverter());\n```\n\n---\n\n## Threading\n\nMAUI automatically marshals `PropertyChanged` to the UI thread — you can raise\nit from any thread. **However**, direct `ObservableCollection` mutations\n(Add \u002F Remove) from background threads may crash:\n\n```csharp\n\u002F\u002F ✅ Safe — PropertyChanged is auto-marshalled\nawait Task.Run(() => Title = \"Loaded\");\n\n\u002F\u002F ⚠️ ObservableCollection.Add — dispatch to UI thread\nMainThread.BeginInvokeOnMainThread(() => Items.Add(newItem));\n```\n\n---\n\n## Common Pitfalls\n\n| Mistake | Fix |\n|---------|-----|\n| Missing `x:DataType` — bindings silently fall back to reflection | Add `x:DataType` at page root and every `DataTemplate`; enable `XC0025` as error |\n| Forgetting to set `BindingContext` | Set in XAML (`\u003CPage.BindingContext>`) or inject via constructor |\n| Specifying redundant `Mode=OneWay` \u002F `Mode=TwoWay` | Omit `Mode` when using the control's default |\n| ViewModel does not implement `INotifyPropertyChanged` | Use `ObservableObject` from CommunityToolkit.Mvvm or implement manually |\n| Mutating `ObservableCollection` off the UI thread | Wrap mutations in `MainThread.BeginInvokeOnMainThread` |\n| Complex converter chains in hot paths | Pre-compute values in the ViewModel instead |\n| Using `x:DataType=\"x:Object\"` to escape compiled bindings | Restructure bindings; keep compile-time safety |\n| Binding to non-public properties | Binding targets must be `public` properties (fields are ignored) |\n\n---\n\n## References\n\n- [Data binding overview](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002F)\n- [Compiled bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fcompiled-bindings)\n- [Value converters](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fconverters)\n- [Relative bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Frelative-bindings)\n- [Multi-bindings](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Fdata-binding\u002Fmultibindings)\n- [CommunityToolkit.Mvvm](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fcommunitytoolkit\u002Fmvvm\u002F)\n",{"name":5,"license":15,"description":7},"main","5810d492c9b301d8227f932bf87b5c954c4fa4d6","plugins\u002Fdotnet-maui\u002Fskills\u002Fmaui-data-binding","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd","weiflycc.com","2026-11-10 03:26:55",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add weiflycc-cmd\u002Fskills --skill maui-data-binding",{"tool":37,"command":38},"bunx","bunx skills add weiflycc-cmd\u002Fskills --skill maui-data-binding",{"tool":40,"command":41},"pnpm","pnpm dlx skills add weiflycc-cmd\u002Fskills --skill maui-data-binding","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-maui\u002Fskills\u002Fmaui-data-binding\u002FSKILL.md",true,[45],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"references\u002Fdata-binding-api.md","REFERENCE","参考文档",4130,"https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-maui\u002Fskills\u002Fmaui-data-binding\u002Freferences\u002Fdata-binding-api.md",[52,59,66,73,80,87],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M76SGT4WG5682JQJ0V3NSK6X","system-text-json-net11","Provides guidance on new System.Text.Json APIs introduced in .NET 11. It covers typed JsonTypeInfo access via GetTypeInfo\u003CT> and TryGetTypeInfo\u003CT> on JsonSerializerOptions, and the new JsonNamingPolicy.PascalCase static property. Use when serializing or deserializing JSON in .NET 11 applications and needing typed metadata access or PascalCase property naming.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet11\u002Fskills\u002Fsystem-text-json-net11\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M76SGPNZYYV9BCZJW7BF7J8A","nuget-trusted-publishing","Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet OIDC, keyless NuGet publish, migrate from NuGet API key, NuGet\u002Flogin, secure NuGet publishing. DO NOT USE FOR: publishing to private feeds or Azure Artifacts (OIDC is nuget.org only). INVOKES: shell (powershell or bash), edit, create, ask_user for guided repo setup.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fnuget-trusted-publishing\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M76SGHVNBNVM1DMVDYTMAE5G","dotnet-pinvoke","Correctly call native (C\u002FC++) libraries from .NET using P\u002FInvoke and LibraryImport. Covers function signatures, string marshalling, memory lifetime, SafeHandle, and cross-platform patterns. USE FOR: writing new P\u002FInvoke or LibraryImport declarations, reviewing or debugging existing native interop code, wrapping a C or C++ library for use in .NET, diagnosing crashes, memory leaks, or corruption at the managed\u002Fnative boundary. DO NOT USE FOR: COM interop, C++\u002FCLI mixed-mode assemblies, or pure managed code with no native dependencies.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fdotnet-pinvoke\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M76SGDB9Z3GSB1CFW314NC84","csharp-scripts","Run file-based C# apps with the .NET CLI when the user explicitly wants C#\u002F.NET code without creating a project. Use for C# language\u002FAPI experiments, one-file C# apps, small multi-file C# apps composed with `#:include`\u002F`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python\u002FPowerShell-style automation, full projects, or existing app integration.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fcsharp-scripts\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M76SG805T8W764WAKB1NP3CJ","thread-abort-migration","Guides migration of .NET Framework Thread.Abort usage to cooperative cancellation in modern .NET. USE FOR: modernizing code that calls Thread.Abort, catching ThreadAbortException, replacing Thread.ResetAbort, replacing Thread.Interrupt for thread termination, resolving PlatformNotSupportedException or SYSLIB0006 after retargeting to .NET 6+, migrating ASP.NET Response.End or Response.Redirect(url, true) which internally call Thread.Abort. DO NOT USE FOR: code that only uses Thread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException usage — these APIs work identically in modern .NET and need no migration. Also not for projects staying on .NET Framework, or Thread.Abort usage inside third-party libraries you do not control.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fthread-abort-migration\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M76SG2588ZJBE5C51HYJJSKV","migrate-nullable-references","Enable nullable reference types in a C# project and systematically resolve all warnings. USE FOR: adopting NRTs in existing codebases, file-by-file or project-wide migration, fixing CS8602\u002FCS8618\u002FCS86xx warnings, annotating APIs for nullability, cleaning up null-forgiving operators, upgrading dependencies with new nullable annotations. DO NOT USE FOR: projects already fully migrated with zero warnings (unless auditing suppressions), fixing a handful of nullable warnings in code that already has NRTs enabled, suppressing warnings without fixing them, C# 7.3 or earlier projects. INVOKES: Get-NullableReadiness.ps1 scanner script.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fmigrate-nullable-references\u002FSKILL.md",[],[]]