public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var registry = AvaloniaPropertyRegistry.Instance; var parser = new PropertyParser(); var(ns, owner, propertyName) = parser.Parse(new CharacterReader(((string)value).AsSpan())); var ownerType = TryResolveOwnerByName(context, ns, owner); var targetType = context.GetFirstParent <ControlTemplate>()?.TargetType ?? context.GetFirstParent <Style>()?.Selector?.TargetType ?? typeof(Control); var effectiveOwner = ownerType ?? targetType; var property = registry.FindRegistered(effectiveOwner, propertyName); if (property == null) { throw new XamlLoadException($"Could not find property '{effectiveOwner.Name}.{propertyName}'."); } if (effectiveOwner != targetType && !property.IsAttached && !registry.IsRegistered(targetType, property)) { Logger.TryGet(LogEventLevel.Warning)?.Log( LogArea.Property, this, "Property '{Owner}.{Name}' is not registered on '{Type}'.", effectiveOwner, propertyName, targetType); } return(property); }
private void ConnectAnchor(ITypeDescriptorContext context) { // This is a horrible hack to have the control keep the binding alive. _anchor.Tag = this; var window = context.GetFirstParent <Window>(); if (window is null) { var userControl = context.GetFirstParent <UserControl>(); userControl.AttachedToLogicalTree += DelayedSubscribe; } else { Subscribe(window); } }
void ConnectAnchor(ITypeDescriptorContext context) { // This is a horrible hack to have the control keep the binding alive. var window = context.GetFirstParent <Window>(); _anchor.Tag = this; WeakEventHandlerManager.Subscribe <Window, EventArgs, LocalizedResourceExtension>(window, nameof(Window.Closed), DisconnectAnchor); }