문제

내가 구현한 맞춤 구성요소가 있습니다.INotifyPropertyChanged 그리고 IBindableComponent.

그러나 A 속성 데이터를 데이터에 데이터를 만들려고 할 때 디자이너는이 라인을 추가합니다.

this.component11.TestString =
global::WindowsFormsApplication2.Properties.Settings.Default.Setting;

TextBox와 마찬가지로 바인딩을 만드는 대신 다음을 수행합니다.

this.textBox2.DataBindings.Add(new System.Windows.Forms.Binding(
   "Text",
   global::WindowsFormsApplication2.Properties.Settings.Default,
   "Setting2",
   true,
   System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

나는 디자이너가 단순히 다음과 같은지 살펴볼 것이라고 생각했을 것입니다.IBindableComponent 구현되고, 그렇다면, 할당 코드 대신 바인딩 코딩을 생성하십시오.

이것이 내 사용자 정의 구성 요소가 아닌 텍스트 상자에서 작동하는 이유에 대한 아이디어가 있습니까?

내 사용자 정의 구성 요소는 다음과 같습니다.

public partial class Component1 : Component, INotifyPropertyChanged, IBindableComponent
    {
        public Component1()
        {
            InitializeComponent();
        }

        public Component1(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        private string teststring;
        [Bindable(true)]
        public string TestString
        {
            get
            {
                return teststring;
            }
            set
            {
                if (teststring != value)
                {
                    teststring = value;
                    FirePropertyChanged("TestString");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region IBindableComponent Members

        private BindingContext bindingContext = null;

        public BindingContext BindingContext
        {
            get
            {
                if (null == bindingContext)
                {
                    bindingContext = new BindingContext();
                }

                return bindingContext;
            }
            set { bindingContext = value; }
        }

        private ControlBindingsCollection databindings;

        public ControlBindingsCollection DataBindings
        {
            get
            {
                if (null == databindings)
                {
                    databindings = new ControlBindingsCollection(this);
                }
                return databindings;
            }
            set { databindings = value; }
        }

        #endregion
    }

print("code sample");
도움이 되었습니까?

해결책

노력하다:

[ DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden ),
  EditorBrowsable( EditorBrowsableState.Advanced ),
  Browsable( false ) ]
public BindingContext BindingContext {
    ...
}

[ ParenthesizePropertyName( true ),
  RefreshProperties( RefreshProperties.All ),
  DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
  Category( "Data" ) ]
public ControlBindingsCollection DataBindings {
   ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top