1

私はC#&XAML開発の新人です。いくつかのテキスト ボックスを含むメトロ アプリを作成しました。これらのテキスト ボックスは、C# コードの 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);



    }
4

2 に答える 2

1

いつもの「何を試しましたか?」は飛ばします。Marginにプロパティを設定することで、おそらく必要なものを得ることができると質問してくださいTextBox-プロパティは、一種のパ​​ディングとしてコントロール サイズの周りに「スペース」を追加します (コントロールの範囲にスペースを追加するプロパティMarginと混同しないでください)。 )Padding

于 2013-03-06T16:27:42.450 に答える
1

あなたが本当に何をしているのかわかりませんがMargin、テキストボックスのプロパティを使用してください。コントロールの周りにどれだけのスペースがあるかを定義します。

詳細については、 MSDNを参照してください。

于 2013-03-06T16:28:30.690 に答える