This project is read-only.

RibbonTabItem doesn't inherit own dependency property

Feb 28, 2013 at 9:12 AM
Edited Feb 28, 2013 at 11:01 AM
Hey,

I'm trying to do a localization for a fluent ribbon application, but I've got a problem that the TranslationProvider isn't inherited to RibbonTabItems.
public static class LocalizationScope
{
    public static readonly DependencyProperty TranslationProviderProperty = DependencyProperty.RegisterAttached(
        "TranslationProvider",
        typeof (ITranslationProvider),
        typeof(LocalizationScope),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)
        );

    public static void SetTranslationProvider(DependencyObject obj, ITranslationProvider value)
    {
        obj.SetValue(TranslationProviderProperty, value);
    }

    public static ITranslationProvider GetTranslationProvider(DependencyObject obj)
    {
        return (ITranslationProvider)obj.GetValue(TranslationProviderProperty);
    }
}
In XAML it looks like this:
<fluent:MetroWindow ... Standard namespaces ...
           xmlns:mvvm="http://www.galasoft.ch/mvvmlight"
           xmlns:fluent="clr-namespace:Fluent;assembly=Fluent"
           xmlns:converters="clr-namespace:Fluent.Metro.Converters;assembly=Fluent"
           xmlns:lex="clr-namespaceShowCase.Library.Language"
           xmlns:res="clr-namespace:ShowCase.Language"

Here comes my dependency property!

      lex:LocalizationScope.TranslationProvider="{TranslationProvider res:Translations}">

    ... Resources ...

        <fluent:Ribbon SelectedTabIndex="{Binding SelectedRibbon, Mode=TwoWay}" IsQuickAccessToolBarVisible="False">
            <fluent:Ribbon.Menu>
                <fluent:Backstage Header="{lex:Translate Options, Converter={StaticResource ToUpperConverter}}">
                    <fluent:BackstageTabControl>
                        <fluent:BackstageTabItem Header="{lex:Translate Save}"/>
                    </fluent:BackstageTabControl>
                </fluent:Backstage>
            </fluent:Ribbon.Menu>

            <fluent:RibbonTabItem x:Name="Home" Header="{lex:Translate Home, Converter={StaticResource ToUpperConverter}}">
                <fluent:RibbonGroupBox>
                    <fluent:Button LargeIcon="Images\appbar.refresh.png" Header="{lex:Translate Reload}"
                                         Command="{Binding ReloadCommand, Mode=OneWay}"/>
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>
        </fluent:Ribbon>

        <TextBlock Text="{lex:Translate Hello}" />
</fluent:MetroWindow>
And in the Background basically this happens:
result = LocalizationScope.GetTranslationProvider(obj);

return result.Translate(key);
This works for all items except for RibbonTabItem and everything in this Tab.
Even obj is set to the Right RibbonTabItem but I don't get a ITranslationProvider back, because it seems that the inheritance is ignored somewhere.

In an older application with Office 2010 style this doesn't happen.

Can anyone tell me where it goes wrong?
Mar 7, 2013 at 11:18 PM
Does this only happen when using the metro theme or even when using the office 2010 theme?
Mar 14, 2013 at 1:50 PM
This does happen with both styles. I still don't know why it gets lost in the first way, but when i change the language later on it will work, so i simply set the language on startup at OnLoaded and it works.