简体   繁体   English

ASP.NET中的本地资源,是否可以修改控件大小?

[英]Local resources in ASP.NET, is it possible to modify control sizes?

I have a ASP.NET multi-language application with 3 local resources for Hindi-English-Spanish. 我有一个ASP.NET多语言应用程序,其中3种用于印地语-英语-西班牙语的本地资源。

The definitions for all the "xxxxResource1.Text" & "xxxxResource1.ToolTip" work just fine according to the primary language selected on the browser. 根据在浏览器上选择的主要语言,所有“ xxxxResource1.Text”和“ xxxxResource1.ToolTip”的定义都可以正常工作。

My question is if there is a way to handle the sizes of controls inside the same local resource file, I ask this because, as you can imagine, the translation of a word can have less or more characters than the english version. 我的问题是,是否有一种方法可以处理同一本地资源文件中控件的大小,我之所以这么问,是因为您可以想象,一个单词的翻译可以比英文版本包含更少或更多的字符。 So I would like to do some adjustments to grid columns, textboxes, labels, etcetera if the application is viewed in another Language. 因此,如果要使用其他语言查看应用程序,我想对网格列,文本框,标签等进行一些调整。

I wouldn't like to leave everything open by no defining the width of a button so it could addapt to the text shown on it, but rather prefer to be able to specify % or px values when required. 我不想通过不定义按钮的宽度来使所有内容保持打开状态,以便它可以添加到其上显示的文本中,而是希望能够在需要时指定%或px值。

If Local Resources can not handle that kind of information about the controls, what would be a good approach to specify controls' sizes according to language? 如果本地资源无法处理有关控件的那种信息,那么根据语言指定控件大小的一种好方法是什么?

PD. PD。 Actually the first time when I tried to set these values in Local Resource my first thought was to use "xxxxResource1.Width" but didn't work 实际上,当我第一次尝试在本地资源中设置这些值时,我的第一个念头是使用“ xxxxResource1.Width”,但没有用

Thanks in advance for any hint on this. 在此先感谢您提供任何提示。 Regards! 问候!

If you use the meta:resourcekey attribute , you can bind the control's properties to resources, which will automatically be applied to the control when it is rendered. 如果使用meta:resourcekey属性 ,则可以将控件的属性绑定到资源,将在呈现控件时将其自动应用于控件。

Well, sort of. 好吧,有点。

It only works for properties that are strings. 它仅适用于字符串属性。 So it works for Text , Tooltip , and CssClass . 因此它适用于TextTooltipCssClass But Width isn't a string (it's a Unit , whatever that is) and Style , believe it or not, isn't a string either-- it's a sort of dictionary object. 但是Width不是字符串(无论是Unit ,还是String), Style (不管您相信与否)都不是字符串-它是一种字典对象。

My recommendation would be to define a few CSS classes for various widths and apply them along with the text. 我的建议是为各种宽度定义一些CSS类,并将其与文本一起应用。

Example button markup: 按钮标记示例:

<asp:Button ID="Button1" runat="server" meta:resourcekey="Button1Resource1" Text="This actually gets ignored"  />

Resx: Resx:

<data name="Button1Resource1.Text" xml:space="preserve">
    <value>Localized text goes here</value>
</data>
<data name="Button1Resource1.CssClass" xml:space="preserve">
    <value>Width120</value>
</data>

CSS: CSS:

.Width120 { width: 120px }

Not ideal, but simple enough. 不理想,但足够简单。 With maybe a dozen CSS classes you can cover a significant range of width possibilities. 也许有一打CSS类,您就可以涵盖各种宽度的可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM