1
在WPF,tb.HorizontalContentAlignment = HorizontalAlignment.Center
作品:为什么HorizontalContentAlignment不像WPF中那样在Silverlight中工作?
WPF XAML:
<Window x:Class="TestText2343434.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel x:Name="MainContent" Margin="10" HorizontalAlignment="Left"/>
</Grid>
</Window>
WPF代码背后:
using System.Windows;
using System.Windows.Controls;
namespace TestText2343434
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TextBox tb = new TextBox();
tb.Width = 30;
tb.MaxLength = 1;
tb.HorizontalContentAlignment = HorizontalAlignment.Center;
MainContent.Children.Add(tb);
}
}
}
在Silverlight中,tb.HorizontalContentAlignment = HorizontalAlignment.Center
不起作用:
的Silverlight XAML:
<UserControl x:Class="TestContent222.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<StackPanel x:Name="MainContent" Margin="10" HorizontalAlignment="Left"/>
</Grid>
</UserControl>
的Silverlight代码背后:
using System.Windows;
using System.Windows.Controls;
namespace TestContent222
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
TextBox tb = new TextBox();
tb.Width = 30;
tb.MaxLength = 1;
tb.HorizontalContentAlignment = HorizontalAlignment.Center;
MainContent.Children.Add(tb);
}
}
}
为了让HorizontalContentAlignment
在Silverlight中像在WPF中一样工作,我需要做些什么?
5年以后,接受答案怎么样?下面的各种选择将做:) – 2016-01-19 17:38:37
Upvote撤回...等待接受答案的5年就足够了:P – 2016-01-21 15:17:43