Skip to content

Commit

Permalink
Added selector bindiing
Browse files Browse the repository at this point in the history
  • Loading branch information
cuhsat committed May 2, 2022
1 parent 9dce0e8 commit e301d21
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Caliban.Nano/UI/ViewBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,6 +98,7 @@ public static void Default()
AddResolver<RadioButton>(BindProperty("IsChecked"));
AddResolver<Calendar>(BindProperty("SelectedDate"));
AddResolver<DatePicker>(BindProperty("SelectedDate"));
AddResolver<Selector>(BindItem("SelectedItem"));
AddResolver<ItemsControl>(BindProperty("ItemsSource"));
AddResolver<DocumentViewer>(BindProperty("Document"));
AddResolver<ContentControl>(BindView("Content"));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e301d21

Please sign in to comment.