Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand your question correctly you want to bind the culture for a specific <code>TextBlock</code>.</p> <p>You can't bind the properties of a <code>Binding</code> so binding <code>ConverterCulture</code> won't work.</p> <p>There is a <code>Language</code> property on <code>FrameworkElement</code> which works fine to set like this</p> <pre><code>&lt;TextBlock Language="en-US" Text="{Binding Number, ElementName=BoxPanelElement, StringFormat={}{0:C}}"/&gt; </code></pre> <p>However, when trying to bind this property I get a weird exception<br> <em>I'm probably going to ask a question on this exception myself</em></p> <blockquote> <p>Binding for property 'Language' cannot use the target element's Language for conversion; if a culture is required, ConverterCulture must be explicitly specified on the Binding.</p> </blockquote> <p>According to this answer by <a href="https://stackoverflow.com/users/98713/thomas-levesque">Thomas Levesque</a> this should be possible though so maybe I did something wrong.. <a href="https://stackoverflow.com/questions/5606789/wpf-xmllang-language-binding">WPF xml:lang/Language binding</a></p> <p>All I got working was using an attached behavior which in turn updated <code>Language</code> when MyCulture updated.</p> <pre><code>&lt;TextBlock local:LanguageBehavior.Language="{Binding MyCulture}" Text="{Binding MyNumber, ElementName=BoxPanelElement, StringFormat={}{0:C}}"/&gt; </code></pre> <p><em>LanguageBehavior</em></p> <pre><code>public class LanguageBehavior { public static DependencyProperty LanguageProperty = DependencyProperty.RegisterAttached("Language", typeof(string), typeof(LanguageBehavior), new UIPropertyMetadata(LanguageBehavior.OnLanguageChanged)); public static void SetLanguage(FrameworkElement target, string value) { target.SetValue(LanguageBehavior.LanguageProperty, value); } public static string GetLanguage(FrameworkElement target) { return (string)target.GetValue(LanguageBehavior.LanguageProperty); } private static void OnLanguageChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) { FrameworkElement element = target as FrameworkElement; element.Language = XmlLanguage.GetLanguage(e.NewValue.ToString()); } } </code></pre>
 

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