From e301d21549945d67377332ad79690d1fed35ab23 Mon Sep 17 00:00:00 2001 From: Christian Uhsat Date: Mon, 2 May 2022 15:56:00 +0200 Subject: [PATCH] Added selector bindiing --- src/Caliban.Nano/UI/ViewBinder.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Caliban.Nano/UI/ViewBinder.cs b/src/Caliban.Nano/UI/ViewBinder.cs index 748c6a0..681c3c5 100644 --- a/src/Caliban.Nano/UI/ViewBinder.cs +++ b/src/Caliban.Nano/UI/ViewBinder.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Data; namespace Caliban.Nano.UI @@ -97,6 +98,7 @@ public static void Default() AddResolver(BindProperty("IsChecked")); AddResolver(BindProperty("SelectedDate")); AddResolver(BindProperty("SelectedDate")); + AddResolver(BindItem("SelectedItem")); AddResolver(BindProperty("ItemsSource")); AddResolver(BindProperty("Document")); AddResolver(BindView("Content")); @@ -126,6 +128,11 @@ private static Resolver BindGuard(string name) return (t, s) => Bind(t, s, name, BindingUtils.GetPathWithGuard(t.Name)); } + private static Resolver BindItem(string name) + { + return (t, s) => Bind(t, s, name, BindingUtils.GetPathWithItem(t.Name)); + } + private static Resolver BindView(string name) { return (t, s) => Bind(t, s, name, BindingUtils.GetPathWithView(t.Name)); @@ -176,7 +183,8 @@ private static class BindingUtils { public static bool IsGuard(string path) => path.StartsWith("Can"); public static string GetPathWithGuard(string name) => $"Can{name}"; - public static string GetPathWithView(string name) => $"{name}.View"; + public static string GetPathWithItem(string name) => $"{name}Selected"; + public static string GetPathWithView(string name) => $"{name}.View"; public static DependencyProperty? GetDependencyProperty(string property, Type type) => DependencyPropertyDescriptor.FromName(property, type, type)?.DependencyProperty; }