J'ai un composant personnalisé sur lequel j'ai implémenté INotifyPropertyChanged
et IBindableComponent
.ApplicationConnexion à des composants personnalisés
Cependant, lorsque je tente de DataBind une propriété, le concepteur ajoute cette ligne :
this.component11.TestString =
global::WindowsFormsApplication2.Properties.Settings.Default.Setting;
au lieu de créer une fixation comme il le fait avec une zone de texte:
this.textBox2.DataBindings.Add(new System.Windows.Forms.Binding(
"Text",
global::WindowsFormsApplication2.Properties.Settings.Default,
"Setting2",
true,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
j'aurais pensait que le concepteur chercherait simplement à voir si IBindableComponent
est implémenté et si c'est le cas, générer le codage de liaison au lieu du code d'affectation.
Des idées pourquoi cela fonctionne avec une zone de texte et pas mon composant personnalisé?
Voici mon composant personnalisé:
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");
Cela ne semble pas fonctionner, le concepteur génère toujours le code: this.component11.TestString = global: : TestApplicationSettings.Properties.Settings.Default.TestSetting; Au lieu du code de liaison correct. D'autres idées à regarder? Merci d'avoir répondu. – Clint
Attendez, ça marche. J'avais juste besoin de recompiler mon composant, de le supprimer et de le rajouter après avoir fait les changements suggérés. Merci beaucoup! – Clint