绑定属性,但后面没有更改代码

时间:2014-02-24 09:41:22

标签: c# wpf binding properties code-behind

我有一个带有FontFamily属性的UserControl(继承自Control Class,它是Bindable属性)。

在继承自Adorner的第二类中,我尝试将FontFamily(以及其他一些Fontstuff)绑定到我的DependencyStuff以重新获取实际的FontStuff。

这里有一些代码:

public class CaretAndMarker : System.Windows.Documents.Adorner
{

   public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(CaretAndMarker), new PropertyMetadata(new FontFamily("Arial")));

   public System.Windows.Media.FontFamily FontFamily
   {
        get { return (System.Windows.Media.FontFamily)this.GetValue(FontFamilyProperty); }
        set { this.SetValue(FontFamilyProperty, value); }
    }

   /// <summary>
   /// Binds an Property of Anchestor to this
   /// </summary>
   /// <param name="dp">this DependencyProperty</param>
   /// <param name="Path">Anchestor Path</param>
   /// <param name="typ">Type of Anchestor</param>
   private void bind(DependencyProperty dp, string Path, Type typ)
   {
       //Binding
       Binding BFS = new Binding();
       BFS.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typ, 1);
       BFS.Path = new PropertyPath(Path);
       var bes = this.SetBinding(dp, BFS);
   }


   public CaretAndMarker(System.Windows.UIElement adornedElement)
       : base(adornedElement)
   {

       //Binding FontFamily
       bind(FontFamilyProperty, "FontFamily", typeof(txtField));

    ....

但Binding似乎无法正常工作。 如果我在UserControl中更改FontFamily,CaretAndMarker类的FontFamily将不会被更新。

你有什么建议吗?

0 个答案:

没有答案