几何尺寸与公差论坛

 找回密码
 注册
查看: 349|回复: 2

如何修改成一个自定义属性?并支持数据绑定

  [复制链接]
发表于 2023-10-6 13:49:37 | 显示全部楼层 |阅读模式
要将SerButton属性修改为具有自定义逻辑的属性,您可以将其改为依赖属性。依赖属性允许您添加属性更改通知并支持数据绑定。

以下是将SerButton属性改为依赖属性的示例代码:

csharp
public static readonly DependencyProperty SerButtonProperty = DependencyProperty.Register(
    "SerButton", typeof(string), typeof(YourViewModel), new PropertyMetadata(StrON));

public string SerButton
{
    get { return (string)GetValue(SerButtonProperty); }
    set { SetValue(SerButtonProperty, value); }
}
 楼主| 发表于 2023-10-6 13:50:36 | 显示全部楼层
                this.SetResourceReference(SerButtonProperty, SelectedAxis.SerButton);
 楼主| 发表于 2023-10-6 13:51:19 | 显示全部楼层
                            <Helper:ImageButton x:Name="OpenCloseBtn" HorizontalAlignment="Center" Style="{StaticResource HorizontalImageButtonStyle}" Height="32"  BackText ="{Binding ElementName=ucAxis,Path=SerButton}" BackImage="{Binding SerButton ,Converter={StaticResource StringToImgeConverter}}" Command="local:UcAxissStatus.SetServoEnable"/>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-4-28 04:14 , Processed in 0.129206 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表