Browse Source

Added TextBox XAML style.

Watermark not yet working - need to either expose properties controlling
visibility or add XAML multi-bindings.
Steven Kirk 10 years ago
parent
commit
42da070678

+ 44 - 0
samples/XamlTestApplicationPcl/TextBox.paml

@@ -0,0 +1,44 @@
+<Styles xmlns="https://github.com/perspex">
+  <Style Selector="TextBox">
+    <Setter Property="Background" Value="White"/>
+    <Setter Property="BorderBrush" Value="#ff707070"/>
+    <Setter Property="BorderThickness" Value="2"/>
+    <Setter Property="Padding" Value="2"/>
+    <Setter Property="Template">
+      <ControlTemplate>
+        <Border Name="border"
+                Background="{TemplateBinding Background}"
+                BorderBrush="{TemplateBinding BorderBrush}"
+                BorderThickness="{TemplateBinding BorderThickness}"
+                Padding="2">
+          <ScrollViewer CanScrollHorizontally="{TemplateBinding CanScrollHorizontally}"
+                        HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}"
+                        VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}">
+            <StackPanel Margin="{TemplateBinding Padding}">
+              <TextBlock Name="floatingWatermark"
+                         Foreground="#ff007ACC"
+                         FontSize="10"
+                         Text="{TemplateBinding Watermark}"
+                         IsVisible="{TemplateBinding IsFloatingWatermarkVisible}"/>
+              <Panel>
+                <TextBlock Name="watermark"
+                           Opacity="0.5"
+                           Text="{TemplateBinding Watermark}"
+                           IsVisible="{TemplateBinding IsWatermarkVisible}"/>
+                <TextPresenter Name="PART_TextPresenter"
+                               CaretIndex="{TemplateBinding CaretIndex}"
+                               SelectionStart="{TemplateBinding SelectionStart}"
+                               SelectionEnd="{TemplateBinding SelectionEnd}"
+                               Text="{TemplateBinding Text}"
+                               TextWrapping="{TemplateBinding TextWrapping}"/>
+              </Panel>
+            </StackPanel>
+          </ScrollViewer>
+        </Border>
+      </ControlTemplate>
+    </Setter>
+  </Style>
+  <Style Selector="TextBox:focus /template/ Border#border">
+    <Setter Property="BorderBrush" Value="Black"/>
+  </Style>
+</Styles>

+ 1 - 0
samples/XamlTestApplicationPcl/XamlTestApp.paml

@@ -10,6 +10,7 @@
     <StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TabControl.paml"/>
     <StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TabItem.paml"/>
     <StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TabStrip.paml"/>
+    <StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.TextBox.paml"/>
     <StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.Window.paml"/>
   </Application.Styles>
 </Application>

+ 3 - 0
samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj

@@ -151,6 +151,9 @@
     <EmbeddedResource Include="TabItem.paml">
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="TextBox.paml">
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
   </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 1 - 1
src/Perspex.Controls/TextBox.cs

@@ -129,7 +129,7 @@ namespace Perspex.Controls
 
         protected override void OnTemplateApplied()
         {
-            _presenter = this.GetTemplateChild<TextPresenter>("textPresenter");
+            _presenter = this.GetTemplateChild<TextPresenter>("PART_TextPresenter");
             _presenter.Cursor = new Cursor(StandardCursorType.Ibeam);
         }