You must adhere to dependency property naming conventions, where the DependencyProperty identifier field is named like the property with a Property suffix:private static readonly DependencyProperty State1ColorProperty = DependencyProperty.Register(nameof(State1Color), typeof(Brush), typeof(WifiControl));public Brush State1Color{ get { return (Brush)GetValue(State1ColorProperty); } set { SetValue(State1ColorProperty, value); }}绑定应该如下所示.设置 UpdateSourceTrigger=PropertyChanged 毫无意义.The Binding should then look like shown below. Setting UpdateSourceTrigger=PropertyChanged is pointless.Fill="{Binding ElementName=_this, Path=State1Color}" 或Fill="{Binding State1Color, ElementName=_this}" 或Fill="{Binding State1Color, RelativeSource={RelativeSource AncestorType=UserControl}}"我还建议将您的属性重命名为 StateXBrush 而不是 StateXColor,因为它们是画笔,而不是颜色.I'd also recommand to rename your properties to StateXBrush instead of StateXColor, because they are Brushes, not Colors. 这篇关于自定义控件填充颜色不随依赖属性更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-21 08:23