【问题标题】:How can i call a Method/value in Resource Dictionary file from App.xaml.cs如何从 App.xaml.cs 调用资源字典文件中的方法/值
【发布时间】:2018-08-07 07:21:55
【问题描述】:

我有一些带有TextBlock Control 的 .xaml 文件

<TextBlock Text="........." Name="myTxt" /> 

我需要来自 App.xaml.cs 的 Text 属性设置值“Something”

public partial class App : Application
{
    public static string something { get; set; }
}

【问题讨论】:

标签: wpf xaml app.xaml


【解决方案1】:

这应该可行:

<TextBlock xmlns:local="clr-namespace:WpfApp1" Text="{x:Static local:App.something}" Name="myTxt" />

...前提是您将“WpfApp1”更改为 App 类的命名空间:

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static string something { get; set; } = "something...";
    }
}

【讨论】:

  • @PeterTomašovič:你试过这个吗?
猜你喜欢
  • 2012-09-02
  • 1970-01-01
  • 2017-06-18
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 1970-01-01
相关资源
最近更新 更多