[2.0] Binding Title of LayoutAnchorable

May 23, 2012 at 6:38 PM

I set a binding of a LayoutAnchorable's Title (non-MVVM usage) and got:

A 'Binding' cannot be set on the 'Title' property of type 'LayoutAnchorable'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

I'd really prefer not to switch this app over to an MVVM style to get binding for this.  Do I need to use a LayoutItemContainerStyleSelector or is there a different route?

May 24, 2012 at 7:14 PM

Ended up using this:

                <Style TargetType="{x:Type ad:LayoutItem}">
                    <Setter Property="Title"
                            Value="{Binding Model.TabName}" />

And putting a TabName model on any anchorable I cared about dynamically updating.  Nicely, the LayoutAnchorable.Title's set in xaml were not erased if the binding failed.

May 24, 2012 at 7:15 PM

I agree, it will be very usefull to have LayoutContent (then the derived  LayoutDocument and LayoutAnchorable) as DependencyObject with the Title as a Dependency property to allow doing Binding.

May 24, 2012 at 7:45 PM

The proposed solution would be usefull if I could use an attached property like this


                <Style TargetType="{x:Type avalonDock:LayoutItem}">
                    <Setter Property="Title"
                            Value="{Binding Model.TitleBinding.Title}" />
                            <avalonDock:LayoutDocument >
                                <Border local:TitleBinding.Title="{Binding DocumentName}" Background="Yellow"/>
                                <Border local:TitleBinding.Title="{Binding AnchorableName}" Background="Orange"/>



where the attached property is



    public class TitleBinding : DependencyObject
        public static string GetTitle(DependencyObject obj)
            return (string)obj.GetValue(TitleProperty);

        public static void SetTitle(DependencyObject obj, string value)
            obj.SetValue(TitleProperty, value);

        public static readonly DependencyProperty TitleProperty = DependencyProperty.RegisterAttached("Title",
           typeof(string), typeof(TitleBinding), new UIPropertyMetadata(string.Empty));



but this solution is not working