【问题标题】:Multiple Dependency Properties多个依赖属性
【发布时间】:2015-11-26 22:28:11
【问题描述】:

我目前正在开发一个用户控件并坚持使用依赖对象类的自定义属性 IsEnabled 被识别,但不是 FooText

XAML:

<ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" 
                   sc:TouchScrolling.IsEnabled = "true" 
                   Grid.Row="0" Grid.Column="1">

我需要在 sc:TouchScrolling 元素上设置更多属性,但 VS 一直抱怨找不到该属性。

TouchScrolling 元素继承自 Dependency Object

public class TouchScrolling : DependencyObject
    {
        public bool IsEnabled
        {
            get { return (bool)GetValue(IsEnabledProperty); }
            set { SetValue(IsEnabledProperty, value); }
        }

public static readonly DependencyProperty IsEnabledProperty =
            DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(TouchScrolling), new UIPropertyMetadata(false, IsEnabledChanged));


//FooText is not recognized
  public string FooText
        {
            get { return (string)GetValue(FooTextProperty); }
            set { SetValue(FooTextProperty, value); }
        }

【问题讨论】:

    标签: c# wpf dependencyobject


    【解决方案1】:

    您似乎缺少 FooText DependencyProperty...

    public static readonly DependencyProperty FooTextProperty =
                DependencyProperty.RegisterAttached("FooText", typeof(string), typeof(TouchScrolling), null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 2011-07-22
      • 2012-08-26
      相关资源
      最近更新 更多