バックエンドの静的プロパティを xaml フロントエンドにバインドする必要がある場合がありますが、練習後は 2 つのバインド方法があります。
たとえば、バックグラウンドでクラスを宣言し、そのクラスには静的変数が含まれているとします。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 静态变量绑定
{
public class Const
{
public static string Name {
get; set; } = "Tony";
}
}
バインディングのパスの割り当て (非推奨)
<Button Margin="5" Height="30" Width="100" Content="{Binding Path=(local:Const.Name)}"></Button>
ただし、この書き方ではプロンプトは表示されません。
バインディングのソース割り当て
<Button Margin="5" Height="30" Width="100" Content="{Binding Source={x:Static local:Const.Name}}"></Button>
この書き方にはヒントがあります。