private static bool TryBindSelectedItems(Type viewModelType, string path, PropertyInfo property, FrameworkElement element, ElementConvention convention, IList selectedItems) { var parentApplied = ConventionManager.GetElementConvention(typeof(Selector)) .ApplyBinding(viewModelType, path, property, element, convention); var index = path.LastIndexOf('.'); index = index == -1 ? 0 : index + 1; var baseName = path.Substring(index); var propertyInfo = viewModelType.GetPropertyCaseInsensitive("Selected" + baseName); if (propertyInfo == null || !typeof(IList).IsAssignableFrom(propertyInfo.PropertyType)) { return(parentApplied); } var target = (IList)propertyInfo.GetValue(element.DataContext, null); CollectionHelper.Bind(selectedItems, target); return(true); }
private static void ConfigureKeyBinding() { var trigger = Parser.CreateTrigger; Parser.CreateTrigger = (target, triggerText) => { if (triggerText == null) { ElementConvention defaults = ConventionManager.GetElementConvention(target.GetType()); return(defaults.CreateTrigger()); } string triggerDetail = triggerText.Replace("[", string.Empty).Replace("]", string.Empty); string[] splits = triggerDetail.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (splits[0] == "Key") { var key = (Key)Enum.Parse(typeof(Key), splits[1], true); return(new KeyTrigger { Key = key }); } return(trigger(target, triggerText)); }; }
static VisibilityBinder() { convention = new ElementConvention { ElementType = typeof(FrameworkElement), GetBindableProperty = element => UIElement.VisibilityProperty, ParameterProperty = "Visibility", }; }
static EnabledBinder() { convention = new ElementConvention { ElementType = typeof(FrameworkElement), GetBindableProperty = element => UIElement.IsEnabledProperty, ParameterProperty = "IsEnabled", CreateTrigger = () => new EventTrigger { EventName = "IsEnabledChanged" } }; }
private static BindingExpression GetBindingExpression(FrameworkElement control) { if (control == null) { return(null); } ElementConvention convention = ConventionManager.GetElementConvention(control.GetType()); DependencyProperty bindableProperty = convention?.GetBindableProperty(control); return(bindableProperty != null ? control.GetBindingExpression(bindableProperty) : null); }
private static bool Bind(ElementConvention convention, FrameworkContentElement element, string bindPath, PropertyInfo property, Type viewModelType) { var bindableProperty = convention.GetBindableProperty(element); if (bindableProperty == null || element.GetBindingExpression(bindableProperty) != null) { return(false); } var binding = new Binding(bindPath); ConventionManager.ApplyBindingMode(binding, property); ConventionManager.ApplyValueConverter(binding, bindableProperty, property); ConventionManager.ApplyStringFormat(binding, convention, property); ConventionManager.ApplyValidation(binding, viewModelType, property); ConventionManager.ApplyUpdateSourceTrigger(bindableProperty, element, binding, property); BindingOperations.SetBinding(element, bindableProperty, binding); return(true); }
public static bool Bind(this ElementConvention elementConvention, BindablePropertyInfo propertyInfo, FrameworkElement element) { return(elementConvention.ApplyBinding(propertyInfo.Property.PropertyType, propertyInfo.Path, propertyInfo.Property, element, elementConvention)); }