Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Great!</p> <p>I'm going to do the same thing you did here. Yeah, I have a solution but I'm not sure if it works till now.</p> <p>First, we need a LocalizationManager which holds a dictionary.</p> <p>For example, if you need to localize a user account window, just do this</p> <pre><code>&lt;TextBlock Text="something, UsernameKey"&gt; </code></pre> <p>And the localizationManager will map UsernameKey to "Username" or other language</p> <p>Second, a xaml extension which find the value of the key from LocalizationManager.</p> <p>I wonder if this custom extension could derived from Binding extension, if so, this'll be very easy, just create a Binding Object to the target. If not, I think holding a WEAK reference to the UIElement by xaml extension to dynamic update the text is proper.</p> <p>This solution is simple but not generic. There're some language read from right to left. It asks the application to show content from right to left.</p> <p>So, I have another generic solution but more complex.</p> <p>Instead of xaml extension, we use an attach dependency property.</p> <p>Do it like this:</p> <pre><code>&lt;TextBlock LocalizationManager.LocalizationKey="UsernameKey" /&gt; </code></pre> <p>So, the problem now is how to set "Text" property by LocalizationManager?</p> <p>We use adapters, LocalizationManager will search proper adapter for type "TextBlock"</p> <p>So, when the application is booting, we register some adapters to LocalizationManager:</p> <pre><code>LocalizationManager.Current.RegisterAdapter&lt;TextBlock&gt;(new TextBlockAdapter()) </code></pre> <p>This solution is more generic, it supports any kind of control if you provide adapter, but as you see, this solution needs more work and much more complex than the former one.</p> <p>I hope these design solutions could help you~</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload