|
-
April 9th, 2012, 08:54 AM
#1
Convert a string to a DependencyObject
Alright, i've googled this until my computer was blue in the face and have gotten nowhere.
I want to assign a behaviour to some textboxes through a for loop. I added a messagebox to make sure the BlockName.Name was correct...it is. The TextBoxes are already created and named bl1, bl2, etc. I only need to assign the behaviour to 4 on this tab, but others have 20+. With the following i get "cannot convert from string to System.Windows.DependencyObject.
public MainPage()
{
InitializeComponent();
for (int a = 1; a < 4; ++a)
{
TextBox BlockName = new TextBox();
BlockName.Name = "bl" + a;
MessageBox.Show(BlockName.Name.ToString());
Interaction.GetBehaviors(BlockName.Name).Add(new Watermark());
}
}
If i change the last line to:
Interaction.GetBehaviors(BlockName).Add(new Watermark());
I do not get the effect. If i assign each box individually it works perfectly. What am I doing wrong???
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|