动态设置属性 WPF 应用程序

Set Properties Dynamically WPF Application

我有一个 属性 作为:Button1 System.Windows.Thickness 10,10,10,10 按钮 名称为 Button1。我可以设置为

Propertis.Setting.Default.Button1 = _margin;

我有很多类似的按钮,其中我的 xaml name n 属性 name 是相同的,所以我想要的是将边距设置为动态

Button option = sender as Button;

Properties.Settings.Default.option = _margin;

可以实现吗?如果是怎么办?

由于设置中存储的值是键值对,您可以将任何与Button控件同名的属性设置为

 Button option = sender as Button;

 Properties.Settings.Default[option.Name] = _margin;