Loading...
 
Multi-Language Add-In for Visual Studio

Multi-Language Add-In for Visual Studio


Hiding texts in XAML files

Germany

Back in Version 6.03 I made a significant change to the handling of texts in XAML files, using a new markup extension, for example:

XAML Localization with m:Lang
Content="{m:Lang Apply}"


This is described in the forum page XAML Localization with a markup extension

Now I have made another significant change, this time related to hiding texts in XAML files.

When you hide an attribute, Multi-Language will now insert the attached property

XAML
m:Hide.Option="node"

for example

XAML
<TextBlock Text="Three" m:Hide.Option="node" />


That is all that is required to hide the texts in this XAML node.

This is a big simplification. Previously Multi-Language added the x:Uid attribute to identify the XAML node. It then stored the fact that a property was hidden in the project database.

In the new version, Multi-Language does not add x:Uid or x:Name to a node either when you hide it, or when you select it for translation. In addition, Multi-Language stores nothing related to the node in the project database.

The attached property m:Hide.Option is defined in the file MlExtension.cs/.vb along with the markup extension used to fetch translated texts. The definition is extremely minimal.

C#
public enum HideOption { node, tree, none }

public static class Hide
{
  public static HideOption GetOption ( Object obj )
  {
    return HideOption.node ;
  }
  public static void SetOption ( Object obj, HideOption value )
  {
  }
}


The property value is not stored at all. In particular, it is not a dependency property, and it may be applied to objects which are not dependency objects.

As a result, the property can be applied almost anywhere.

For example on a setter

XAML
<style x:Key="TBStyle" TargetType="TextBlock">
  <Setter Property="FontFamily"   Value="Courier New" m:Hide.Option="node" />
  <Setter Property="FontStyle"    Value="Italic"      m:Hide.Option="node" />
  <Setter Property="TextWrapping" Value="Wrap"        m:Hide.Option="node" />
  <Setter Property="FontSize"     Value="12" />
</Style>

Alternativ usage m:Hide.Option="tree"


In the previous example, it would be more convenient to hide the properties at a higher level, for the whole style.

This is possible using the alternative value m:Hide.Option="tree".

XAML
<style x:Key="TBStyle" TargetType="TextBlock" m:Hide.Option="tree">
  <Setter Property="FontFamily"   Value="Courier New" />
  <Setter Property="FontStyle"    Value="Italic"      />
  <Setter Property="TextWrapping" Value="Wrap"        />
  <Setter Property="FontSize"     Value="12" />
</Style>


This option would effectively mark the style node and all its child nodes as hidden.

Note:
Multi-Language recognizes this option, but there is no GUI support for inserting it. If you want to use this option, you must add it by hand.

You cannot apply the option directly to a Resources node, but if you place your resources within a resource dictionary, you can apply it to the resource dictionary. So you could effectively hide all strings in your resources in the following way.

XAML
<Window.Resources>
  <ResourceDictionary m:Hide.Option="tree">

  </ResourceDictionary>
</Window.Resources>


Finally, if you wanted to revert the m:Hide.Option="tree" at a lower level in the tree structure, this is possible with m:Hide.Option="none".