Steven's profileThornton on WPFBlogListsGuestbookMore Tools Help

Thornton on WPF

Tried JavaFX. Tried Flex. WPF 'Best thing since sliced bread'
May 10

WPF TextBox Watermark – The Easy Way!


I like the TextBox Prompts you get on iPhones and other newer software where you have a gray text representation of what your expected to type into the box ‘TextBox Watermark’ some people call them. All the examples I could Google seemed very complicated and some even used code-behind – I wanted to do everything in XAML.

I already had a <Style> created for my rounded textboxes

 

<!--ROUND TEXTBOX -->
<Style x:Key="roundTextBox" TargetType="{x:Type TextBox}">
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
    <Setter Property="AllowDrop" Value="true" />
    <Setter Property="Background" Value="Transparent"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="FontFamily" Value="Segoe UI" />
    <Setter Property="FontSize" Value="12" />
    <Setter Property="Padding" Value="8,5,3,3" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBox}">
                <Grid>
                    <Border x:Name="BorderBase" Background="White" BorderThickness="1.4,1.4,1,1"
                            BorderBrush="Silver" CornerRadius="10" />
                    <Label x:Name="TextPrompt" Content="{TemplateBinding Tag}" Visibility="Collapsed" Focusable="False"  Foreground="Silver"></Label>
                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" Foreground="{DynamicResource OutsideFontColor}" />
                </Grid>
                <ControlTemplate.Triggers> 
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsFocused" Value="False"></Condition>
                            <Condition Property="Text" Value=""></Condition>
                        </MultiTrigger.Conditions>
                        <MultiTrigger.Setters>
                            <Setter Property="Visibility" TargetName="TextPrompt" Value="Visible"></Setter>
                        </MultiTrigger.Setters>
                    </MultiTrigger>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="BorderThickness" TargetName="BorderBase" Value="2.4,2.4,1,1"></Setter>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Foreground" Value="DimGray" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

  1. I placed a Label control behind the ContentHost of the TextBox and bound it’s content to the ‘Tag’ property.
  2. Next we created a MultiTrigger to hide the TextPrompt when the roundTextBox gets focus or we’ve entered text.
  3. This means we can set the text of the prompt on each instance of our roundTextBox simply by entering the text into the Tag

<TextBox Tag="Client Name" Style="{StaticResource roundTextBox}" Name="txtNameCriteria" Height="26" HorizontalAlignment="Left" Margin="104,30,0,0" VerticalAlignment="Top" Width="164" />

This is how the roundTextBox’ behave now – when we give a textbox focus the prompt disappears and when it loses focus the prompt reappears.

image

How Easy is That!!

Regards

Steve Thornton
Thornton Software UK
steve@thorntonsoftware.co.uk
May 04

WPF Themes – let your creative side come out

I’m told that ‘programmers will NEVER be graphic designers and graphic designers will NEVER be programmers!’

We probably all agree that it does require a different mindset for both.  Microsoft’s Expression Blend seems to be a
great product for designers, I have to make do with the slightly less graphical Visual Studio.

I found a very useful resource for us non designers at CodePlex recently the WPF Themes gives a very good example of what you can create in XAML and it gave me an idea for a screen I was working on. Unfortunately my screen used ‘Side Tabs’ and the Tab styling in the WPF Themes didn’t seem to like this. It is interesting to see how Microsoft staff are creating styles and templates. The example below is what I created using my own styles to get my sideways tabs working.

 

image

I like the ease at which you can use Triggers to handle states – this allows you to cater for hover, selected, disabled and even default button states. I believe the WPF Themes use the new VisualStateManager which may make this even simpler in the future.

 

Steve Thornton

Thornton Software UK

April 13

WPF DataTemplates for ListItems

Below is a partial screenshot (Fig.1) from our new version of Hotel Desk we’ve created at Thornton Software.

One of the things that’s really impressed us with WPF is the freedom you have with the lookless controls, in particular the listBoxes, listViews and comboBoxes. Your imagination is about the only thing limiting how your lists look.

One of the things we wanted to achieve in our booking record was to lessen the number of times a user has to interact with a dialog boxes while entering bookings. Our list box below is made up of a DataTemplate which contains an Expander control and a Canvas for the booking details. We’ve been able to use Binding and Validation to control input to the items and our test users have given positive feedback to its speed and smoothness of use. Only one item can be expanded at a time (Giving a useful focus we can use) and if all items are collapsed then buttons such as ‘Copy’ or ‘Remove’ disable as required.
 
blogPic  Fig. 1

We’re very pleased with how WPF is allowing us to create a smoother richer environment for our users

Steve Thornton
Thornton Software UK

January 22

WPF and Me!

I've been writing software for over twenty years and I've tried most development system available.
 
Last year I had a look at JavaFX and later last year I spent considerable (unpaid) time working with Adobe's Flex 3. I have liked some of the features of these systems and Adobe should be commended for what they have done. However I found Flex (and in my case AIR) is still not fit for LOB (Line of Business) development.
 
Returning to Visual Studio - I have been amazed how much the development team have advanced WPF! In my opinion it is now way ahead of Sun and Adobe with their offerings in RIA applications. I've also noticed that Microsoft seem to be more engaging with it's developer community (Us small guys!) cetainly I have found that the elitism that existed with them previously has dissapeared! I have been on a crash course since December to learn WPF and I'm addicted! My productivity once I understood how 'Binding' is so important to WPF and developed stratagies for data access, has been excellent.
 
As a project to enhance my WPF skills I decided to re-develop an old hotel booking system, I feel that until you use a system in anger you don't find the real pro's and con's of a development system. Three weeks of development later and I'm not far from finished! Another week or two and I think I will have a reasonably commercial product. I'll let you know how I get on and I'll post blogs of some of the techniques I develop on the way.
 
Early screenshot of Hotel Desk 3
 
 

 

 
Steve Thornton
Thornton Software UK
 
 
 
 
 
 

Steven Thornton

Occupation
Location
Interests
Developed database systems using Clipper 5, VB, C#, WPF
Thanks for visiting!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
by