简体   繁体   中英

Creating and positioning a control with c# on windows phone

I'm creating an app where a user is filling in a form with several text boxes. They can add or remove text boxes based on how many they wish. I'm having trouble with adding and positioning a new control. Here's what I have so far:

TextBox textOne = new TextBox();
textOne.Text = "Lorem ipsum";
textOne.Height = 20;
textOne.Width = 50;
textOne.Margin.Left = 20;

The problem is the final line where I try to set the margin to 20 and it says: "Cannot modify the return value of 'System.Windows.FrameworkElement.Margin' because it is not a variable".

Am I not using the correct method (well clearly I'm not) or am I just going about this the completely wrong way?

尝试使用Thickness对象:

textOne.Margin = new Thickness(20, 0, 0, 0); // left, top, right, bottom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM