C# 在充满文本框的StackPanel中添加空间
我是C# 在充满文本框的StackPanel中添加空间,c#,xaml,textbox,microsoft-metro,stackpanel,C#,Xaml,Textbox,Microsoft Metro,Stackpanel,我是C#和XAML开发的新手。我用几个文本框创建了一个metro应用程序。这些文本框通过C#code中的StackPanel加载到XAML数据中,必须对其进行硬编码。问题是,我不知道如何在每个文本框之间添加一些空格。有人有主意吗? 守则: private void AddLastestCreatedField() { // Load the last created Field From DB DBFunction.FieldTypes latestF
C#
和XAML
开发的新手。我用几个文本框创建了一个metro应用程序。这些文本框通过C#code中的StackPanel加载到XAML数据中,必须对其进行硬编码。问题是,我不知道如何在每个文本框之间添加一些空格。有人有主意吗?
守则:
private void AddLastestCreatedField()
{
// Load the last created Field From DB
DBFunction.FieldTypes latestField;
DBFunction.Class1 myDBClass = new DBFunction.Class1();
latestField = myDBClass.GetLastestField();
// add new textbox and put it on the screen
var dragTranslation = new TranslateTransform();
//Generate the TextBox
TextBox fieldTextBox = new TextBox();
fieldTextBox.Name = "fieldTextBox_" + latestField.ID.ToString();
fieldTextBox.FontSize = 15;
fieldTextBox.Background.Opacity = 0.8;
ToolTip toolTip = new ToolTip();
toolTip.Content = latestField.Description;
ToolTipService.SetToolTip(fieldTextBox, toolTip);
fieldTextBox.IsReadOnly = true;
// Add Drag and Drop Handler for TextBox
fieldTextBox.ManipulationMode = ManipulationModes.All;
fieldTextBox.ManipulationDelta += fieldTextBox_ManipulationDelta;
fieldTextBox.ManipulationCompleted += fieldTextBox_ManipulationCompleted;
fieldTextBox.RenderTransform = dragTranslation;
dragTranslationDict.Add(fieldTextBox.Name, dragTranslation);
fieldTextBox.RenderTransform = dragTranslation;
// Add TextBox to a List to control later
TxtBoxList.Add(fieldTextBox);
// Generate TextBlock for each TextBlock
TextBlock fieldTextBlock = new TextBlock();
// fieldTextBlock.Name = "fieldTextBlock_" + cnt.ToString();
fieldTextBlock.TextAlignment = TextAlignment.Right;
fieldTextBlock.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right;
fieldTextBlock.Name = "fieldTextBlock_" + latestField.ID.ToString();
fieldTextBlock.Text = latestField.Name;
fieldTextBlock.FontSize = 15;
fieldTextBlock.Height = 33;
// Add Drag and Drop Handler for TextBlock
var dragTranslation2 = new TranslateTransform();
fieldTextBlock.RenderTransform = dragTranslation2;
dragTranslationDict2.Add(fieldTextBlock.Name, dragTranslation2);
// Add TextBlock to a list to control later
TxtBlockList.Add(fieldTextBlock);
TextBoxStack.Children.Add(fieldTextBox);
TextBlockStack.Children.Add(fieldTextBlock);
}
我将跳过通常的“您尝试了什么?”问题,并说您可能可以通过在
文本框上设置Margin
属性来获得所需的内容Margin
属性将在控件大小周围添加“空格”作为一种填充(不要与Padding
属性混淆,该属性将在控件范围内添加空间)我不知道您真正在做什么,但可以使用文本框的Margin
-属性。它定义控件周围有多少空间
有关更多信息,请参阅。使用XAML。不要在这样的代码中创建UI元素。如果需要显示多个(动态)元素,请参阅然后使用ItemsControl
。基于XAML的技术需要比以前的传统全代码UI更高、更抽象的思维水平technologies@HighCore啊,但是我很喜欢我的“通过LINQPad的WPF”测试平台……这都是手工完成的;)Thx对于两者,我知道代码可能有点奇怪。谢谢你的回复,终于成功了。