1
我試圖在Windows通用應用程序上生成一個動態表單,並且存在保證金問題。XAML保證金錯誤
我喜歡讓Radiobutton和Textbox在邊界0的左側。 問題在於文本框不能停留在左邊,我有兩個控件,邊界爲0,不知何故,文本框正在推到屏幕的右側。
這是我運行應用程序後的結果。
我的腳本文件名MainPage.xaml.cs中項目AppTestTrash
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace AppTestTrash
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
//Add dynamic RadioButton
var dynamicRadiobtn = new RadioButton();
dynamicRadiobtn.Name = "testme";
dynamicRadiobtn.Height = 30;
dynamicRadiobtn.Width = 50;
dynamicRadiobtn.Margin = new Thickness(0, 100, 0, 0);
dynamicForm.Children.Add(dynamicRadiobtn);
//Add dynamic texbox
var dynamicTextbox = new TextBox();
dynamicTextbox.Name = "testme2";
dynamicTextbox.Height = 30;
dynamicTextbox.Width = 50;
dynamicTextbox.Margin = new Thickness(0, 120, 0, 0);
dynamicForm.Children.Add(dynamicTextbox);
}
}
}
XAML文件MainPage.xaml中的Windows通用應用的輸出結果
<Page
x:Class="AppTestTrash.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppTestTrash"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Loaded="Page_Loaded">
<Grid Name="mainGrid" BorderBrush="AliceBlue" Width="500" Height="500" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" BorderThickness="2">
<StackPanel Name="dynamicForm" BorderThickness="1">
</StackPanel>
</Grid>
</Page>