将自定义依赖项属性绑定到自定义WPF样式

设计inheritance的Expander时遇到问题。 我的目的是在切换按钮和默认Expander标头中的文本后面有一个进度条。

我有这个XAML代码,它给我标题中的进度条。 这是一种定制风格。

                             

这工作正常但我无法绑定控制进度百分比的自定义依赖项属性。

  public class ProgressExpander : Expander { static ProgressExpander() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressExpander), new FrameworkPropertyMetadata(typeof(ProgressExpander))); } public int Progress { get { return (int)GetValue(ProgressProperty); } set { SetValue(ProgressProperty, value); } } // Using a DependencyProperty as the backing store for Progress. This enables animation, styling, binding, etc... public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register("Progress", typeof(int), typeof(ProgressExpander), new UIPropertyMetadata(0)); } 

这是窗口内的代码:

     

我不确定如何将此依赖项属性进度绑定到样式中ProgressBar中的进度值。

任何帮助,将不胜感激。

在样式中,我们可以使用标准Binding和RelativeSource来设置属性。

  

然后,在窗口中我们只需添加Progress =“50”或绑定到其他地方。

您还需要将Button的背景设置为透明,或者更改某种布局方式,以便查看它。