2013-03-06 2 views
1

신생아입니다. C# & XAML 개발 중입니다. 여러 텍스트 상자가있는 메트로 앱을 만들었습니다. 이 텍스트 상자는 C# 코드의 StackPanel을 통해 XAML 데이터에로드되며 하드 코딩해야합니다. 문제는 모든 텍스트 상자 사이에 빈 공간을 추가 할 수있는 방법이 없다는 것입니다. 누구 한테 아이디어가 있니? 강령 :StackPanel에 공간 추가하기 텍스트 상자로 가득

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); 



    } 
+0

XAML을 사용하십시오. 그런 식으로 UI 요소를 만들지 마십시오. UI에 여러 (동적) 항목을 표시해야하는 경우 'ItemsControl'을 사용하십시오. XAML 기반 기술은 기존의 모든 코드 UI 기술보다 훨씬 더 추상적이고 추상적 인 사고 방식을 필요로합니다. –

+0

@HighCore Aww,하지만 저는 "WPF via LINQPad"테스트 장비를 좋아합니다. 손으로); – JerKimball

답변

1

내가 보통 건너 뛸 것 "당신이 시도 무엇을?" 질문에 따라 Margin 속성을 TextBox에 설정하면 필요한 정보를 얻을 수 있습니다. Margin 속성을 사용하면 제어 크기 주변에 공백이 추가되어 공백이 추가됩니다 (공백을 추가하는 Padding 속성과 혼동하지 않아야 함). 내부 제어 범위)

1

실제로 무엇을해야할지 모르지만 입력란의 Margin 속성을 사용하십시오. 그것은 얼마나 많은 공간이 컨트롤 주위에 있을지를 정의합니다.

자세한 내용은 MSDN을 참조하십시오.

+0

Thx 모두 내가 알고있는 코드가 조금 이상하게 보일 수 있습니다. 그러나 마침내 그것이 당신에게 호의를 보였다. – user2140676

관련 문제