如何从 WPF 中的资源文件加载控件大小



通常在winforms中,您可以从FormName.resx文件中加载控件文本以及其他属性(如大小)。

同样,我们可以从 WPF 中的资源文件加载控件文本,如下所示;

<Button Content="{x:Static res:Resources.ButtonText}" Height="100" Width="150">

但我也想从 .resx 文件加载高度和宽度。如何在 WPF 中实现它?

右键单击 Visual Studio 中的.resx文件,选择"Open With->XML (Text) Editor",然后在文件底部添加类型为 double 的数据值:

<data name="Height" type="System.Double, mscorlib">
    <value>20</value>
</data>

然后,您应该能够像往常一样使用此资源:

<Button ... Height="x:Static res:Resources.Height" />

最新更新