1

Closed

Issues with backstage content localization using WPF Localization Extension

description

Could you please check whether this is a Fluent issue?

Fluent 2.1.0.0
WPF Localization Extension 2.2.1.0

How to reproduce:
  1. Start an app with a ribbon and a backstage (XAML example see below).
  2. Open the backstage via app menu button. Then close the backstage.
  3. Switch the language in the app like this:
LocalizeDictionary.Instance.SetCurrentThreadCulture = true;
CultureInfo newCulture = CultureInfo.GetCultureInfo("de");
LocalizeDictionary.Instance.Culture = newCulture;
  1. The LocExtension updates all bound properties (e.g. Header or Text). Backstage.Header gets updated too.
  2. Open the backstage again. All the content items bound properties have the "old" values.
    In the Debug output there is a message:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.FrameworkElement', AncestorLevel='1''. BindingExpression:Path=Parent; DataItem=null; target element is 'BackstageAdorner' (Name=''); target property is 'Parent' (type 'DependencyObject')
Switching the language at runtime before opening the backstage works (that means, the content items bound properties get the right values), but only one time.

Using following XAML:
<UserControl x:Class="Test"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:fluent="clr-namespace:Fluent;assembly=Fluent"
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
            lex:LocalizeDictionary.DesignCulture="en-US"
            lex:ResxLocalizationProvider.DefaultAssembly="PlatiScan.Ui"
            lex:ResxLocalizationProvider.DefaultDictionary="Resources"            
             >

<fluent:Ribbon>
        <fluent:Ribbon.Menu>
            <fluent:Backstage Header="{lex:Loc}">
                <fluent:BackstageTabControl>
                    <fluent:BackstageTabItem x:Name="informationBackStageItem" Header="{lex:Loc}" HorizontalAlignment="Left">
                        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                            <StackPanel  Width="500" Margin="30" HorizontalAlignment="Left">
                                <TextBlock x:Name="textProductInfo" FontSize="18" Text="{lex:Loc}"/>
                            </StackPanel>
                        </ScrollViewer>
                    </fluent:BackstageTabItem>
                </fluent:BackstageTabControl>
            </fluent:Backstage>
        </fluent:Ribbon.Menu>
</fluent:Ribbon>
</UserControl>

file attachments

Closed Jan 30, 2015 at 9:59 AM by batzen
Fixed in third party component

comments

batzen wrote Oct 21, 2014 at 6:39 PM

Could you post a full repro? The code you posted does not include your resources etc..

dymanoid wrote Oct 22, 2014 at 8:38 AM

Here is a VS 2012 solution based on the Fluent.Sample.Foundation example. Just play with the "Switch language" button.

Thank you in advance for your support!

batzen wrote Oct 22, 2014 at 9:24 PM

Still don't know who's bug this is, but i found a way to fix it.
Have to do some more tests.
Will push my change and release v3.0.1 till sunday i think.

batzen wrote Oct 25, 2014 at 1:37 PM

Fixed in changeset 213cd2f57601

batzen wrote Oct 26, 2014 at 12:58 PM

** Closed by batzen 10/26/2014 4:58AM

dymanoid wrote Oct 28, 2014 at 3:22 PM

Thank you for the bugfix, it helped for a a simple scenario.

However, we are now encountering this issue (Fluent 3.0.2) in a more complex scenario: using PRISM (modularity) and MEF2 (Microsoft.Composition).

I have prepared a small test solution. I would be very thankful if you could take a look on this.

dymanoid wrote Oct 28, 2014 at 3:24 PM

Here is the attachment.

batzen wrote Oct 29, 2014 at 8:43 PM

Found the bug.

batzen wrote Oct 29, 2014 at 8:53 PM

Fixed in changeset 98257d736fe0

batzen wrote Oct 29, 2014 at 8:55 PM

Too early... Causes other problems...

batzen wrote Oct 29, 2014 at 11:40 PM

So, i finally found out what's causing this.
The problem is that the Localization Extensions look at the visual tree.
It's done in line 73 of ParentChangedNotifierHelper.cs by calling
try { depObjParent = VisualTreeHelper.GetParent(depObj); }
This does not work when Adorners are used (which is done in the backstage) because the visual parent of the adorner is the adornerdecorator of the window thus leading the extension to the window and this property
lex:ResxLocalizationProvider.DefaultAssembly="FluentLexTest2"
Maybe they better should use the logical tree (as it's done for the datacontext etc.).

As your localization offers german, i guess you speak german:
Oder einfach gesagt, der bug liegt, meiner Meinung nach, nicht im Ribbon.
Ich wüsste auch nicht, wie ich das ausbügeln kann. Der zwischenzeitliche fix führt zwar dazu, dass deine lokalisierung funktioniert, allerdings funktioniert dann das backstage nicht mehr.

dymanoid wrote Oct 31, 2014 at 9:33 AM

Thank you for your deep investigation! I suppose we should continue in English so other people may follow the discussion. I've created an issue for the WPF Localization extension and would wait for a developers team feedback.

dymanoid wrote Dec 9, 2014 at 3:27 PM

Since there is no feedback from the WPF Localization extension authors (unfortunately), we've found a work around to solve this issue by our selves. We have moved the ribbon from our class library directly into the main EXE assembly, now it works as expected.

This issue can be closed.

MrCircuit wrote Jan 6, 2015 at 11:29 PM

Hi,

I'm sorry for the delay, but I finally found time to work on this issue from our side (WPFLocalizeExtension). Your hint was great - by merging your approach with the LogicalTreeHelper and the existing approach with the VisualTreeHelper (in exactly this order), I was finally able to cover this issue as well as some special cases on the other side. Thanks again for your help.

This issue can be closed - it was no bug of Fluent and was solved on our side.

Best regards