Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I marked the answer by Ray Burns using the StaticResource extension as the accepted answer, I think alot of the details about that approach are perfect. I also wanted to show another idea - using T4 templates to generate 'loose' xaml files that are included in the output and parsed at runtime based on the CurrentCulture.</p> <p>The code below is the contents of the file base_block.tt. One detail that is important below is the use of encoding="Unicode" (I assumed Utf-8 would work but the XamlParser would error on some characters when the template specified Utf-8, apparently because of the BOM setting). </p> <pre><code>&lt;#@ template debug="false" hostspecific="false" language="C#" #&gt; &lt;#@ output extension=".xaml" encoding="Unicode"#&gt; &lt;UserControl xml:lang="&lt;#= this.xml_lang #&gt;" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="basic_styles.xaml" /&gt; &lt;ResourceDictionary Source="equations.xaml" /&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; &lt;WrapPanel Style="{StaticResource description_wrap_panel_style}"&gt; &lt;TextBlock x:Name="c_textblock" Style="{StaticResource description_textblock_style}" AutomationProperties.Name = "&lt;#= this.textblock_automation_name #&gt;"&gt; &lt;#= this.textblock_constant_C_contents #&gt; &lt;/TextBlock&gt; &lt;TextBlock Style="{StaticResource description_textblock_style}" KeyboardNavigation.TabIndex="1"&gt; &lt;#= this.hyperlink_textblock_contents #&gt; &lt;/TextBlock&gt; &lt;TextBox Style="{StaticResource entry_textbox_style}" AutomationProperties.LabeledBy="{Binding ElementName=c_textblock}" KeyboardNavigation.TabIndex="0"&gt; &lt;/TextBox&gt; &lt;/WrapPanel&gt; &lt;/UserControl&gt; &lt;#+ private string xml_lang = @""; private string textblock_constant_C_contents = @""; private string textblock_automation_name = @""; private string hyperlink_textblock_contents = @""; #&gt; </code></pre> <p>base_block.tt can be used in an include in a .tt file that specifies the needed values - for English here is my en.tt file which will generate en.xaml:</p> <pre><code>&lt;# xml_lang = @"en-US"; textblock_constant_C_contents = @"Enter a constant, &lt;Italic&gt;C&lt;/Italic&gt;, that satisfies &lt;InlineUIContainer Style='{StaticResource image_container_style}'&gt; &lt;Image x:Name='formula_11' Source='{StaticResource equation_11}' Style='{StaticResource image_style}' Tag='3.0'&gt; &lt;Image.Height&gt; &lt;MultiBinding Converter='{StaticResource image_size}'&gt; &lt;Binding Mode='OneWay' ElementName='formula_11' Path='Tag'/&gt; &lt;Binding Mode='OneWay' ElementName='c_textblock' Path='FontSize'/&gt; &lt;/MultiBinding&gt; &lt;/Image.Height&gt; &lt;/Image&gt; &lt;/InlineUIContainer&gt;"; textblock_automation_name = @"Enter a Constant, C, that satisfies the following equation: the standard error of the estimate is equal to the constant C over the square root of the sample size"; hyperlink_textblock_contents = @"(&lt;Hyperlink AutomationProperties.Name='More information about the constant C' x:Name='c_hyperlink'&gt;more info&lt;/Hyperlink&gt;)"; #&gt; &lt;#@ include file="base_block.tt" #&gt; </code></pre> <p>Or for French - fr.tt -> fr.xaml:</p> <pre><code>&lt;# xml_lang = @"fr"; textblock_constant_C_contents = @"Entrez une constante, &lt;Italic&gt;C&lt;/Italic&gt;, pour satisfaire &lt;InlineUIContainer Style='{StaticResource image_container_style}'&gt; &lt;Image x:Name='formula_11' Source='{StaticResource equation_11}' Style='{StaticResource image_style}' Tag='3.0'&gt; &lt;Image.Height&gt; &lt;MultiBinding Converter='{StaticResource image_size}'&gt; &lt;Binding Mode='OneWay' ElementName='formula_11' Path='Tag'/&gt; &lt;Binding Mode='OneWay' ElementName='c_textblock' Path='FontSize'/&gt; &lt;/MultiBinding&gt; &lt;/Image.Height&gt; &lt;/Image&gt; &lt;/InlineUIContainer&gt;"; textblock_automation_name = @"Entrez une constante, C, qui satisfait l'équation suivante: l'erreur-type de l'estimation est égale à la constante C sur la racine carrée de la taille de l'échantillon."; hyperlink_textblock_contents = @"(&lt;Hyperlink AutomationProperties.Name=""Plus d'informations sur la constante C""&gt;en savoir plus&lt;/Hyperlink&gt;)"; #&gt; &lt;#@ include file="base_block.tt" #&gt; </code></pre> <p>The French above generates the following .xaml file:</p> <pre><code>&lt;UserControl xml:lang="fr" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="basic_styles.xaml" /&gt; &lt;ResourceDictionary Source="equations.xaml" /&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; &lt;WrapPanel Style="{StaticResource description_wrap_panel_style}"&gt; &lt;TextBlock x:Name="c_textblock" Style="{StaticResource description_textblock_style}" AutomationProperties.Name = "Entrez une constante, C, qui satisfait l'équation suivante: l'erreur-type de l'estimation est égale à la constante C sur la racine carrée de la taille de l'échantillon."&gt; Entrez une constante, &lt;Italic&gt;C&lt;/Italic&gt;, pour satisfaire &lt;InlineUIContainer Style='{StaticResource image_container_style}'&gt; &lt;Image x:Name='formula_11' Source='{StaticResource equation_11}' Style='{StaticResource image_style}' Tag='3.0'&gt; &lt;Image.Height&gt; &lt;MultiBinding Converter='{StaticResource image_size}'&gt; &lt;Binding Mode='OneWay' ElementName='formula_11' Path='Tag'/&gt; &lt;Binding Mode='OneWay' ElementName='c_textblock' Path='FontSize'/&gt; &lt;/MultiBinding&gt; &lt;/Image.Height&gt; &lt;/Image&gt; &lt;/InlineUIContainer&gt; &lt;/TextBlock&gt; &lt;TextBlock Style="{StaticResource description_textblock_style}" KeyboardNavigation.TabIndex="1"&gt; (&lt;Hyperlink AutomationProperties.Name="Plus d'informations sur la constante C"&gt;en savoir plus&lt;/Hyperlink&gt;) &lt;/TextBlock&gt; &lt;TextBox Style="{StaticResource entry_textbox_style}" AutomationProperties.LabeledBy="{Binding ElementName=c_textblock}" KeyboardNavigation.TabIndex="0"&gt; &lt;/TextBox&gt; &lt;/WrapPanel&gt; &lt;/UserControl&gt; </code></pre> <p>At runtime I look at the CurrentCulture, compare that to the generated xaml files that are available, feed the file to XamlReader.Load() and add the resulting Usercontrol in where needed. A small sample app demostrating this is a available <a href="http://s3.amazonaws.com/camiles_WebImages/2009_ADTCAM/T4LocalizationSample_VS2010.zip" rel="nofollow noreferrer">here</a>.</p>
    singulars
    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.
    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