In WPF, tb.HorizontalContentAlignment = HorizontalAlignment.Center
works:
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 Code Behind:
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);
}
}
}
In Silverlight, tb.HorizontalContentAlignment = HorizontalAlignment.Center
does not work:
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 Code Behind:
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);
}
}
}
What do I have to do to make HorizontalContentAlignment
work in Silverlight as it does in WPF?