Browse Source

Merge pull request #300 from mikel785/master

Implemented TextAlignment property for TextBox.
Steven Kirk 10 years ago
parent
commit
8dd668b814

+ 3 - 0
samples/XamlTestApplicationPcl/Views/MainWindow.paml

@@ -63,6 +63,9 @@
                       <TextBox Width="200" Watermark="Floating Watermark" UseFloatingWatermark="True" />
                       <TextBox AcceptsReturn="True" TextWrapping="Wrap" Width="200" Height="150"
                                 Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." />
+                      <TextBox Width="200" Text="Left aligned text" TextAlignment="Left" />
+                      <TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
+                      <TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />
                       <TextBlock Margin="0, 40, 0, 0" Text="CheckBox" FontWeight="Medium" FontSize="20"
                                   Foreground="#212121" />
                       <TextBlock Text="A check box control" FontSize="13" Foreground="#727272" Margin="0, 0, 0, 10" />

+ 1 - 1
src/Perspex.Controls/Presenters/TextPresenter.cs

@@ -180,7 +180,7 @@ namespace Perspex.Controls.Presenters
                     FontFamily,
                     FontSize,
                     FontStyle,
-                    TextAlignment.Left,
+                    TextAlignment,
                     FontWeight))
                 {
                     return formattedText.Measure();

+ 9 - 0
src/Perspex.Controls/TextBox.cs

@@ -37,6 +37,9 @@ namespace Perspex.Controls
         public static readonly PerspexProperty<string> TextProperty =
             TextBlock.TextProperty.AddOwner<TextBox>();
 
+        public static readonly PerspexProperty<TextAlignment> TextAlignmentProperty =
+            TextBlock.TextAlignmentProperty.AddOwner<TextBox>();
+
         public static readonly PerspexProperty<TextWrapping> TextWrappingProperty =
             TextBlock.TextWrappingProperty.AddOwner<TextBox>();
 
@@ -109,6 +112,12 @@ namespace Perspex.Controls
             set { SetValue(TextProperty, value); }
         }
 
+        public TextAlignment TextAlignment
+        {
+            get { return GetValue(TextAlignmentProperty); }
+            set { SetValue(TextAlignmentProperty, value); }
+        }
+
         public string Watermark
         {
             get { return GetValue(WatermarkProperty); }

+ 1 - 0
src/Perspex.Themes.Default/TextBox.paml

@@ -39,6 +39,7 @@
                                SelectionStart="{TemplateBinding SelectionStart}"
                                SelectionEnd="{TemplateBinding SelectionEnd}"
                                Text="{TemplateBinding Text}"
+                               TextAlignment="{TemplateBinding TextAlignment}"
                                TextWrapping="{TemplateBinding TextWrapping}"/>
               </Panel>
             </StackPanel>