[Version 2.0] DynamicResource and Title-Property

Aug 5, 2012 at 12:36 PM


i use AvalonDock in a german project (multi-language GUI).

Every language has a own ResourceDictionary (en-US.xaml, de-DE.xaml, ...) with the strings:

<system:String x:Key="String_Properties">Properties</system:String>
<system:String x:Key="String_Properties">Eigenschaften</system:String>

In AvalonDock 1.3 i use a DynamicResource to set the Title-Property of a DockableContent:
<avalonDock:DockableContent Title="{DynamicResource String_Properties}">

In AvalonDock 2 i tried this:
<avalonDock:LayoutAnchorable Title="{DynamicResource String_Properties}">

This causes problems because the Title-Property is not a DependencyProperty. Does anyone have a solution for this problem?


Aug 6, 2012 at 12:24 AM
Edited Aug 6, 2012 at 12:25 AM


  have you tried a "binding proxy"? ExtendedBinding

  Otherwise try something like this:

  <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
       <Setter Property="Title" Value="{StaticResource STRING}"/>

You should take a look at the MVVM example uploaded here.

Cheers, M

Aug 6, 2012 at 7:00 PM
Edited Aug 6, 2012 at 7:00 PM


thanks for the tips.

I do not use the MVVM pattern but i tried this:

	<Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
		<Setter Property="Title" Value="{DynamicResource String_Properties}"/>

Of course the result is that each LayoutAnchorableItem has the same Title.
Another problem with the code is that the string is not changed if i switch the language (while the software is running).

Also i tried the ExtendedBinding:


<avalonDock:LayoutAnchorable x:Name="LayoutAnchorableProperties"> <!-- TITLE ERROR -->
	<GroupBox Header="{DynamicResource String_Properties}"> <!-- HEADER OK -->

<view:ExtendedBinding Source="{DynamicResource String_Properties}" Target="{Binding ElementName=LayoutAnchorableProperties, Path=Title}" />

The Title of the LayoutAnchorable is always an empty string. hmmm....

I like the new features of AvalonDock 2. Upgrading from version 1.3 to 2 isn't as simple as I thought at the beginning.


Aug 6, 2012 at 11:12 PM

I think you can use a behavior like this (not tested):

    public class LayoutContentAdapter : DependencyObject

        #region Title

        /// <summary>
        /// Title Attached Dependency Property
        /// </summary>
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.RegisterAttached("Title", typeof(string), typeof(LayoutContentAdapter),
                new FrameworkPropertyMetadata((string)null,
                    new PropertyChangedCallback(OnTitleChanged)));

        /// <summary>
        /// Gets the Title property.  This dependency property 
        /// indicates the title to get or set.
        /// </summary>
        public static string GetTitle(DependencyObject d)
            return (string)d.GetValue(TitleProperty);

        /// <summary>
        /// Sets the Title property.  This dependency property 
        /// indicates the title to get or set.
        /// </summary>
        public static void SetTitle(DependencyObject d, string value)
            d.SetValue(TitleProperty, value);

        /// <summary>
        /// Handles changes to the Title property.
        /// </summary>
        private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            LayoutContent layoutContent = d as LayoutContent;
            if (layoutContent != null)
                layoutContent.Title = (string)e.NewValue;



and than use the attached property for your anchorable:

local:LayoutContentAdapter.Title="{DynamicResource  String_Properties}"
Aug 7, 2012 at 4:03 PM


it is a good idea to use a Attached Dependency Property. The title is displayed correctly.

But if I switch the language the title is not changed in LayoutAnchorable. A Translator-Class removes and adds the correct Language-ResourceDictionary an all other controls (GroupBox, TextBox, MenuItem, …) displays the new text.

The problem seems to be difficult… :-(

Apr 26, 2014 at 12:29 AM
I found a workaround using the MVVM sample project.

Step 1 - Put a DependencyProperty on your View class to hold the Title

Step 2 - Bind the View's Title property to the Dynamic Resource
                    <avalonDock:LayoutAnchorable x:Name="MyView"  ContentId="MyView" Title="Does not matter" ... >
                        <views:MyViewClass Title="{DynamicResource MyViewClass_Title}" />

Step 3 - Create a Style that sets the Layout Item's Title from the View's Title
                <!-- workaround for AvalonDock issue where can't set Title to a dynamic resource -->
                <!-- to fix I add a Title property to the View itself and bind that to the DynamicResource -->
                <!-- then when this style runs it sets the layout item title to the View's title property -->
                    <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
                        <Setter Property="Title" Value="{Binding Model.Title}"/>

Step 4 - Modify the PanesStyleSelector class from the MVVM sample project to return The "ViewPropertyStyle" for the View
   public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        if (item is MyViewClass)
            return ViewPropertyStyle;