一、静态绑定
1、新建一个资源字典ButtonStyle
<Style x:Key="btn" TargetType="Button">
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="30"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
在App.xaml引入
<ResourceDictionary Source="ButtonStyle.xaml" />
2、新建一个静态类和非静态类
public static class RegionName
{
public static string Name { get; set; } = "静态绑定";
}
public class Region
{
public string Name { get; set; } = "绑定";
}
3、将这三种使用静态的不同形式在前端绑定
<StackPanel Margin="20">
<TextBlock Text="{x:Static local:RegionName.Name}" Margin="10" />
<TextBlock Text="{Binding Name,Source={StaticResource region}}" Margin="10" />
<Button Style="{StaticResource btn}" Margin="10" Content="静态按钮"/>
</StackPanel>
标签:set,Name,静态,绑定,static,WPF,public,所有
From: https://www.cnblogs.com/guchen33/p/18094419