C
C#2w ago
jjsutton

Struggling to setup Bindings dynamically for my UserControl (WPF TextBox)

I have a custom textbox user control which I am trying to access the different properties from (for storing user input) I am struggling to set them up as each textbox needs to link to a different property...I made a dependancyproperty which then links them through UserInput, where I am attempting to bind each textbox to a different property, however when testing to see if the property is storing the values, its not. Attached is snippets of relevant code as well as an example of one of the properties (please let me know if u need anything more), any input would be appreciated...maybe theres a simpler approach?
No description
No description
No description
No description
No description
8 Replies
Klarth
Klarth2w ago
Generally seems ok besides this. Needs to be the name of the property.
No description
jjsutton
jjsuttonOP2w ago
I tried changing that, however I dont think it is my issue. My textbox property (UserInputProperty) is the one giving me issues. Here is what happens when I input something, as you can see its not reading whats in the textbox correctly
No description
jjsutton
jjsuttonOP2w ago
The user control has the textbox, which is bound to the dependancy property (UserInput)...the idea is to allow me to set where the text needs to be bound to when i use the usercontrol, so that i can set it for multiple properties, as shown in the second image below this
No description
No description
Klarth
Klarth2w ago
Probably needs a two-way binding in the registration here
No description
Klarth
Klarth2w ago
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault) or something close.
jjsutton
jjsuttonOP2w ago
Im not sure if it changes anything, however this is the wrong dependancyproperty you are looking at. I attempted changing it anyway and I also did the same thing for the UserInputProperty, it didnt change anything. I will mess around with the two ways and see if I can get it working. If you have any other ideas please let me know, I am really stuck on this.
jjsutton
jjsuttonOP2w ago
No description
jjsutton
jjsuttonOP2w ago
Figured it out, my style had a property that was messing with it. Once I removed that, it fixed

Did you find this page helpful?