WPF:`{Property}已经由' FrameworkElement'注册。 - 如何将属性附加到基类?

时间:2017-10-04 09:08:18

标签: wpf attached-properties

在WPF应用程序中,我已经定义了PropertyAnalysisTemplate附加属性,我希望它能够用于几种类型的控件。

我这样定义:

componentWillMount() {
  this.setState({ myArray: this.props.yourReduxStoredProp });
}

_sortList() => {
  // retrieve your array from state
  let myArray = this.state.myArray;

  // sort the array locally
  myArray.sort(function(a, b) {
    return b.sortKey- a.sortKey;
  });

  // update the state and, because of the change it state, the component re-renders
  this.setState({ myArray: myArray });
}

一切正常,但在设计师视图中我收到错误:public static readonly DependencyProperty PropertyAnalysisTemplateProperty = DependencyProperty.RegisterAttached( "PropertyAnalysisTemplate", typeof(DataTemplate), typeof(FrameworkElement), new PropertyMetadata( default(DataTemplate)) ); public static DataTemplate GetPropertyAnalysisTemplate(DependencyObject obj) { return (DataTemplate) obj.GetValue(PropertyAnalysisTemplateProperty); } public static void SetPropertyAnalysisTemplate(DependencyObject obj, DataTemplate value) { obj.SetValue(PropertyAnalysisTemplateProperty, value); }

我想我需要为我使用它的特定元素注册它(在这种特定情况下为TextBox),并使用AddOwners添加其他所有者。

但说实话,这对我来说看起来很糟糕。是不是有更多以对象为导向的方法将附加属性注册到基类及其所有后代?

0 个答案:

没有答案