通过更改x:uid在visualstatemanager中进行本地化? [英] Doing localization in visualstatemanager by changing x:uid?

查看:54
本文介绍了通过更改x:uid在visualstatemanager中进行本地化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过向所有元素添加x:uid标签并使用多语言工具包来向UWP应用添加本地化.但是,我遇到了一个问题,在一种情况下,我使用visualstatemanager在狭窄的视图中更改了文本本身.如何在本地化的应用程序中执行此操作?我的第一个想法是将元素的uid更改为新匹配的新文本,我不确定是否有可能.

I am adding localization to my UWP app by adding x:uid tags to all of my elements and using the multilingual toolkit. However I've run into an issue where in one case I change the text itself in the narrow view using the visualstatemanager. How can I do this in a localized app? My first thought would be to change the uid of the element to the new match the new text, I'm not sure it's possible.

这是我想做的事的一个例子,但不起作用:

Here is an example of what I'd like to do, but doesn't work:

 <textblock x:Name="DescriptionTextBox" x:uid="DescriptionTextBox"/> // Normal long description

 ....

              <VisualState x:Name="NarrowState">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0" />
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="DescriptionTextBox.Uid" Value="DescriptionTextBoxShort" /> // Uid of short description

推荐答案

x:Uid在您的TextBlock上没有依赖项属性,因此无法在运行时设置.您可以通过转到XAML页面后面的生成代码(.g.i.cs文件)再次检查.为此,请在构造函数中的InitializeComponent()上单击F12.现在,在生成的代码中找到控件,并开始深入研究对象树:您将不会遇到Uid属性.这是一个 XAML指令,由一个属性.

x:Uid is no dependency property on your TextBlock and can't be set at runtime. You can double check this by going to the generated code behind (.g.i.cs file) of your XAML page. To do this, hit F12 on InitializeComponent() in the constructor. Now locate your control in the generated code and start drilling down the object tree: you won't encounter a Uid property. It's a XAML directive backed up by an attribute.

我通常的解决方法是使用2个TextBlocks(一个折叠)以及长文本和短文本,并在VisualStates中的两个TextBlock之间切换可见性.根据这些TextBlocks的父容器的不同,您可能需要添加一个StackPanel或Grid,因为某些父控件只能有1个子元素.

How I typically solve this is having 2 TextBlocks (one collapsed) with the the long and short text and toggle Visibility between both TextBlocks in your VisualStates. Depending on what the parent container of these TextBlocks is, you might need to add a StackPanel or Grid as some parent controls can only have 1 child element.

这篇关于通过更改x:uid在visualstatemanager中进行本地化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆