多个依赖属性

0 c# wpf dependencyobject

我目前正在处理用户控件并坚持依赖对象类的自定义属性IsEnabled被识别但不是FooText

XAML:

<ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" 
                   sc:TouchScrolling.IsEnabled = "true" 
                   Grid.Row="0" Grid.Column="1">
Run Code Online (Sandbox Code Playgroud)

我需要在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); }
        }
Run Code Online (Sandbox Code Playgroud)

Gle*_*mas 5

你似乎错过了FooText DependencyProperty ......

public static readonly DependencyProperty FooTextProperty =
            DependencyProperty.RegisterAttached("FooText", typeof(string), typeof(TouchScrolling), null);
Run Code Online (Sandbox Code Playgroud)