Thursday, 3 July 2014

TextBox control in XAML

The TextBox control is used to display text that the user can interact with, performing actions such as editing the text or copying it to the clipboard. It is used whenever a free-form response is needed from the user, such as answering the question “What is your name?” In the touch-first world of a Windows app, it is important to realize that the end user may not have a physical keyboard. This means you should expect the user to have to exert
greater effort to type an answer than to pick one from a list, and therefore you should not require typing when picking is an option.
These are the properties that you will most commonly use with TextBox:
• FontFamily: This property is used to specify the font that will be used to render the text
within the control.
• FontSize: This property is used to specify the size of the text within the control.
• IsEnabled: This property indicates whether the user can interact with the control in
any way.
• IsReadOnly: This property indicates whether the contents in the control should be
protected from editing.
• IsSpellCheckEnabled: This property indicates whether the text entered into the control
should have spell-checking performed upon it.
• IsTextPredictionEnabled: This property indicates whether the user should be presented
with autocompletion options for words while they are typing. Using this feature can be
a great help to reducing the effort your user has to exert when typing on an on-screen
keyboard or with their thumbs.
• MaxLength: This property controls the maximum length of the text that can be typed into
the control.
• Text: This property contains the actual text value in the control.
• Width: This property specifies the width of the control. If the length of the text entered
causes it to exceed the width of the control, the portion beyond the edge will not
be displayed.
The following XAML can be used to display the TextBox shown in Figure :
<TextBox Text="The quick brown fox..." FontFamily="Segoe UI" FontSize="48" />


Picture

You can prevent the user from interacting with the control in any way by changing the IsEnabled property to
False. This not only prevents interaction but also changes the way that the control is drawn by giving it a “grayedout”
appearance that users are accustomed to in order to indicate a disabled control. The following XAML
produces the disabled TextBox shown in Figure :
<TextBox Text="The quick brown fox..." IsEnabled="False" FontFamily="Segoe UI" FontSize="48" />
Picture
When you want to prevent editing of the text within the control but still want to maintain the look of the
enabled control and allow users to copy the contents of the control to their clipboard, setting the IsReadOnly to
True can be used to achieve that effect.Because the TextBox control also supports interaction with the end user, events become important. 

These are some of the events you may find yourself responding to for the TextBox:
• GotFocus: This event fires when the TextBox becomes the target of focus on the page.
One common use for GotFocus with TextBox controls is to cause all of the text within
the control to be selected. This allows the user to overwrite the current contents
just by starting to type. This is less effective in the Windows 8 environment because the
touch-optimized TextBox in Windows provides a button to clear the text that the user
can just tap or click.
• TextChanged: This event fires when the Text property of the control is updated. It can be
used for purposes such as validation and triggering the recalculation of computed fields.

What's new in windows phone 8.1

This article describes key new features and improvements in Windows Phone 8.1.

Developer documentationTo provide documentation that is consistent with the converged Windows Runtime developer platform, we have created a single set of developer documentation on MSDN that serves you whether you're building a Windows Phone Store app, or a Windows Store app, or both. It's easy to determine at a glance which platform each piece of content applies to. For example, you can quickly determine by looking at the icons beneath the title of a conceptual topic or an API reference topic whether the API is available to use on Windows, on Windows Phone, or on both.

The icons represent the Windows and Windows Phone operating systems, using a PC and a phone image respectively. In most cases, both a Windows and a Windows Phone icon will appear to indicate that the topic applies to both operating systems. In exceptional cases where a feature area or API is Windows-only, a PC icon will appear alone. If a feature area or API is Windows Phone-only—such as this topic—a phone icon will appear alone. In all cases, hover text on the icon images spells out their meaning.

API reference topics have more platform support details in their Requirements section.

Platform convergence with Windows Store appsWindows Phone 8.1 introduces an important change in the Windows Phone developer ecosystem. In this release, Windows Phone converges with the Windows Store apps platform into a single developer platform that runs the same types of apps—Windows Runtime apps. Platform convergence began in Windows Phone 8, which supports a small subset of Windows Runtime APIs, but which differs from Windows in many core areas. In Windows Phone 8.1, there’s so much more in common—a much larger API set, a similar app model and life cycle, a shared toolset, a common UI framework—Windows Phone and Windows Store app developer platforms truly have become one, single development platform.

Of course there are still some small differences in behavior and supported features between Windows Phone and Windows Store apps. Some of these are the result of timing of the different product cycles, and they may not appear in future releases. Some differences are the result of the different natures of phones and computers, their sizes, and the way people use them. We encourage developers to think in terms of Windows app development—developing for a single Windows Runtime, but targeting two different platforms on phones and computers.

Areas of convergenceApp model and app life cycleA Windows Phone 8.1 app goes through the same app execution states as a Windows Store app and uses the same events to handle launch, activation, and suspension. This means that you can reuse most of your code for saving and restoring state on both Windows Phone and on Windows. The programming model for background tasks also is the same for Windows Phone and Windows Store apps.

Manifest, Build, DeploymentWindows Phone 8.1 adopts the Windows 8 .appx and Windows 8.1 .appx bundle deployment formats, as well as the app manifest file format of Windows Store apps. The Windows Phone 8.1 app manifest file is named Package.appxmanifest. When you build your project, the build process creates an .exe file. When you deploy your app, the app is packaged in a .zip file with the .appx extension.

XAMLWindows Phone 8 apps use XAML to define their UI, but in their XAML they use UI types from a different namespace than those used in the XAML of Windows Store apps. Windows Phone 8.1 adopts the same XAML UI framework as Windows Store apps. So, although we recommend that you tailor your app UI for the appropriate form factor, the design tools, language, and many of the built-in controls are the same.

Windows Phone 8.1 featuresGeolocationThe Windows Runtime geolocation APIs available in Windows Phone 8 continue to be supported in Windows Phone 8.1. Some new classes have been introduced to support better interoperability with other features, such as the new geofencing feature.

GeofencingWindows Phone 8.1 introduces a set of geofencing APIs through which your app can receive notifications when the device enters or leaves an app-specified geographic region. This makes possible app scenarios such as displaying a reminder when the user arrives at home or their workplace, or notifying the user of deals and specials at stores in their area.

MapsWindows Phone 8.1 maps add more features, support for offline tiles, better support for more complex gestures, and improvements in routing.

Background transfersWindows Phone 8.1 supports the Windows.Networking.BackgroundTransfer namespace, through which you can queue uploads and downloads that will be completed by the system in the background even when your app is no longer running. These APIs replace the background transfer service APIs in Windows Phone 8.

MediaMicrosoft Media Foundation is the Microsoft next-generation multimedia platform for Windows. To help developers create media apps that run on Windows Runtime and Windows Phone 8.1, we expose the same Media Foundation APIs in Windows Phone 8.1 as in Windows Store apps, assuming that the API makes sense on a phone. In addition, in Windows Phone 8.1 developers can sync and access media files on the device, even if those file types are not supported in the default Windows Phone 8.1 media player. These two features help developers create unique media apps on Windows Phone 8.1, and support being able to move media apps from Windows 8.1 to Windows Phone 8.1.

Media editingWindows.Media.Editing provides a set of Windows Runtime APIs you can use to create a simple or rich editing app for the phone. This can be a simple video trimmer or a more complex timeline editing app that allows effects to be added via Microsoft Media Foundation Transforms (MFTs). A core concept of the editing API framework is that editing a media file doesn't alter existing source media files. The goal of the APIs is to create a new composition, called a Clip, which contains defined chunks of source clips for audio and video. The properties of a clip are defined by capturing a set of user input. A simple example of this the basic trim operation in which a source clip is loaded and the user picks a new beginning and endpoint in the video, which defines a Clip or MediaClip.

Windows Push Notification Services (WNS)Windows Phone 8.1 also supports the Windows Push Notification Services (WNS) used in Windows Store apps to send toast, tile, and raw updates to the device from a cloud service. For more information about WNS, see Push notification overview. The Microsoft Push Notification Service in Windows Phone Silverlight apps will continue to be supported for backward compatibility.

Managing toast notifications in action centerWindows Phone 8.1 introduces a new action center, along with a set of capabilities developers can use to manage toast notifications through local API calls or by using push notifications. Through these APIs and mechanisms, an app can manage the toast notifications they send to users. Operations include add, remove, replace, and expire. All notification classes are in the Windows.UI.Notifications namespace.

Tiles, toasts, and badgesThe Windows.UI.Notifications and Windows.UI.StartScreen APIs can be used to create toast notifications, create and pin secondary tiles, and keep these experiences updated and fresh for your users. For example, we've also added the capability to update a tile from a background task using XamlRenderingBackgroundTask.

Background audioIn Windows Phone 8.1, the Windows.Media.Playback.BackgroundMediaPlayer class supercedes theMicrosoft.Phone.BackgroundAudio.BackgroundAudioPlayer class in Windows Phone 8. The new class is intended to support the two-process background media playback feature that uses a foreground process for hosting UI and a background process for media playback.

The Windows.Media.Playback.MediaPlayer API is a thin Windows Runtime wrapper for the IMFMediaEngine API, and exposes various events, methods, and properties. The MediaPlayer API provides background access to media playback functionality such as play, pause, stop, fast forward, and rewind. Through this API an app can:

  • Be notified of media playback states via a set of events.
  • Play audio in the background process when the app navigates away from the foreground process. The foreground process can be suspended or terminated.
  • Use XAML for UI without MediaElement in the foreground process, and play media in the background process using MediaPlayer.
DirectXWindows Phone 8 introduced DirectX support for phone apps. In Windows Phone 8.1, support for DirectX is improved with the inclusion of several features previously available only for desktop apps. These include:

  • Direct2D APIs
  • DirectWrite APIs
  • Windows Imaging Component APIs
  • Runtime shader compilation and reflection
  • GPU access to YUV shaders
  • GPU performance counters
  • Graphics diagnostics support
Windows Phone 8.1 has adopted SwapChainBackgroundPanel and SurfaceImageSource, already available to Windows Store apps, so apps can combine DirectX graphics with XAML. This replaces the XAML and Direct3D project templates you use for Windows Phone 8 apps.

Screen recorderWindows Phone 8.1 provides APIs that you can use to create an app that records images or videos of the phone’s screen activity. This way games can upload and share in-game activities. This feature is enabled through enhancements to the Windows.Media.Capture APIs.

CameraWindows Phone 8.1 supports the Windows.Media.Capture APIs, which provide advanced camera capabilities. These are the same APIs that are used for Windows Store apps. This release includes the ability to capture variable photo sequences. These are multiple frames captured in rapid succession, with the option to specify different focus, exposure, and ISO settings for each frame. This feature enables scenarios like generating High Dynamic Range (HDR) images.

UI automationThis feature helps you develop automation peers for your UI elements. Screen readers depend on automation peers, and so does automated testing.

For information about using automation peers for accessibility, see Making your app accessible. Note that some information, such as Implementing keyboard accessibility and the tool links in Testing Tools, does not apply to Windows Phone.

The API reference documentation covers the following namespaces:

Windows.UI.Xaml.AutomationWindows.UI.Xaml.Automation.PeersWindows.UI.Xaml.Automation.ProviderWindows.UI.Xaml.Automation.TextControlsWindows Phone 8.1 uses the same XAML UI framework as Windows Store apps. This is a very significant improvement over Windows Phone 8, because your Windows Phone Store app and Windows Store apps can use the same set of controls, and you can share a lot of UI code. We still recommend that you tailor the UI of each app to the form factor it targets to deliver the best possible customer experience. The same intrinsic controls, such asButtonTextBlockCheckBox, are available on both Windows Phone and on Windows. Controls introduced in Windows 8 such as FlipViewGridViewListViewRichEditBoxPasswordBox, and SemanticZoom are available on the phone in Windows Phone 8.1. The Panorama control has been renamed Hub because it’s now available on both Windows Phone and on Windows. Some controls, such as Pivot, are phone-only. They are available in theWindows.UI.Xaml.Controls.dll assembly and are now under the Windows.UI.XAML.Controls namespace. In a Windows Phone Store app, instead of using the LongListSelector control, you use the ListView and SemanticZoomcontrols.

AnimationsPhone developers need to be able to create apps that have fast and fluid animations to match the Windows Phone design, look, and feel. We expose all Windows Phone 8.1 signature animations through new classes so that XAML developers on Windows Phone 8.1 can apply them to their apps.

Large textWindows Phone 8.1 provides automatic text enlargement. That means that the text size responds automatically when the user changes Text size in Settings > Ease of access. You don’t need to add any code to your app to support this feature, but you can set the IsTextScaleFactorEnabled property on an element to false if you want to opt out of the behavior. You call TextScaleFactorChanged and TextScaleFactor members of theWindows.UI.ViewManagenent.UISettings class to query or react to the user changes to text enlargement settings. The large text feature is only available to Windows Phone apps and is not supported on Windows Store apps.

App bar improvementsIn Windows Phone 8.1 you can use a Binding or a Static (or Theme) Resource reference in an AppBarButton inside the new CommandBar. This is an enhancement from Windows Phone 8.

High contrastWindows Phone offers black and white, high-contrast color schemes, depending on dark or light theme. With Windows Phone 8.1, you can create a “HighContrast” ResourceDictionary in your custom control that automatically applies when the phone’s high-contrast setting is turned on. APIs are provided to detect when the phone is in High Contrast mode, and when the high-contrast settings are changed.

Brushes and text color are not the only elements that you can set up to automatically be updated while in high-contrast mode. You can also switch image resources, and other objects that can be instantiated in XAML.

In-app navigationWhen the user exits a Windows Phone 8.1 app by using the Back button, the app is suspended but not terminated. In Windows Phone 8, the app is terminated when a user exits the app by using the Back button. For information about handling the Back button in a Windows Phone 8.1 app, see Handling the Back Button in a Windows Phone app.

Monetization: Trial experience and in-app purchaseThe trial app and in-app purchase features in Windows Phone 8.1 are largely the same as in Windows Phone 8. One change is that, to offer an app for purchase, instead of using Microsoft.Phone.Tasks.MarketplaceDetailTask you can use the converged Windows.ApplicationModel.Store.CurrentApp.RequestAppPurchaseAsync method. Most of the APIs from the Windows.ApplicationModel.Store namespace are available to Windows Phone Store apps.

WalletWallet on Windows Phone allows users to store their reward cards, tickets, deals, and payment cards in a central location. Using the functionality provided by the Windows Runtime APIs for Wallet inWindows.ApplicationModel.Wallet, you can increase your app's reach by adding items with your unique branding to Wallet. You can also import Wallet cards into Wallet.

ProximityProximity is enhanced in Windows Phone 8.1. Both your Windows Phone app and your Windows Store app can use the same package full name so you won't have to manage different IDs in your code.

In Windows Phone 8.1 we also expand the supported NFC tag scenarios so you can make your tags read-only, write to unformatted tags, and communicate with other contactless cards. Support for these scenarios requires NFC hardware that's using a PN547 chip.

BluetoothBluetooth support has been enhanced in Windows Phone 8.1 using the Windows.Devices.Bluetooth APIs to provide LE support for GATT Client, RFComm, discovery of paired devices and more. We've also added background capabilities for use with LE and RFComm. For example, you can use a Bluetooth background task with an app such as a heart rate monitor or use triggers to launch an app’s background agent when a Bluetooth event occurs.

SecuritySecurity features for Windows Phone 8.1 are tightly converged with existing Windows Store apps security. Improvements to security include support for several standard cryptographic algorithms which are not currently supported, enabling third-party apps to use certificates for common operations, and support for virtual smart cards for enterprise scenarios such as S/MIME, Secure Browsing, and VPN.

GlobalizationWindows Phone 8.1 works toward globalization convergence with Windows. Windows Phone 8.1 supports many new Windows locales. Additionally, Windows Phone 8.1 enables Modern Resource Technology (MRT). MRT is a technology introduced in Windows 8 that implements the dynamic loading of app resources at run time in the Visual Studio design surface.

CalendarWindows Phone 8.1 supports many of the Windows.ApplicationModel.Appointments APIs that provide calendar capabilities. These are the same APIs that are in Windows Store apps. Windows Phone 8.1 also introduces the ability to create app calendars. These are calendars that are owned by your app but that can be displayed and modified by the built-in calendar experience or even other apps, if you allow it.

BrowserWindows Phone 8.1 supports the Internet Explorer 11 platform, exposed via the WebView control. This includes advanced performance for HTML5-based apps with enhanced layout and runtime capabilities, which support the next generation of web-based apps, gaming, and media consumption. This includes the Windows implementation of WebGL that you use create dynamic 2D and 3D graphics for games and interactive content.

InputWindows Phone 8 games have native programming support to raise and lower the software input panel (SIP), also known as the on-screen keyboard. In Windows Phone 8 there is a property on CoreWindow calledIsKeyboardInputEnabled. If a developer wants to create a game that easily targets both Windows Phone 8.1 and Windows 8.1, the Windows Runtime platform would seem like a great way to accomplish this. Unfortunately, the support to programmatically raise and lower the SIP currently is not available for Windows Runtime apps. Windows Phone 8.1 apps can programmatically show the SIP to support raw text input through CoreWindow events.

External display supportExternal display features would allow a user to share their phone screen from their Windows Phone 8.1 device to a nearby device, either wirelessly or using a cable, without having to understand the complexities of the technologies leveraged to accomplish it. With Windows Phone 8.1, a developer or RSP can mirror the phone screen to a PC via USB cable.

File access and file pickersWindows Phone 8.1 fully implements the Windows.Storage API, except for some methods related to stream-based files.

Windows Phone Store apps can now use file pickers to open or save a file or choose a folder. For more info, seeWorking with File Pickers. However, a Windows Phone Store app calls different methods than a Windows Store app.

RoamingWindows Phone 8.1 adds support for roaming data. A Windows Phone app opts in to roaming simply by storing data in the Roaming folder. Roaming only happens when the lock screen is engaged and the device is not busy.

Taking full advantage of roaming requires keeping in mind several design considerations:

  • Roaming data for an app is limited to 100 KB. Rather than roaming actual content, use references to content.
  • Arrange data as a group of settings or as a single file if it needs to be internally consistent and automatically synced.
  • Handle the DataChanged event, which indicates that the roaming data has been updated as the result of a sync operation.

Share contractWindows Phone 8.1 implements the Share contract but with a different user experience than in Windows Store apps because Windows Phone doesn’t have charms flyout. Sharing supports URI, file, text, and bitmap (with a size limitation yet to be determined); sharing may not support HTML and RTF formats.

SD card accessWindows Phone 8 supports read-only access to the SD card; Windows Phone 8.1 provides read/write access. An app can only see and work with files when it has registered as a handler for that file type. For more info, see Access the SD card in Windows Phone apps. To test your app with this new feature, the Windows Phone Emulator now includes support for a simulated SD card.

App installation on SD cardsWindows Phone 8.1 lets users opt to install apps on the optional SD card, or move apps that are already installed to the SD card. If you don't want your app installed on the removable SD card, select Prevent installation to SD cardson the Application page of Manifest Designer.

Development toolsWindows Phone EmulatorWindows Phone 8.1 emulator adds support for different physical screen sizes and for multi-touch input with the mouse. It also adds improved networking support to simplify setup, configuration, and access to network resources and to reduce troubleshooting.

With the emulator's Additional Tools, you can test many features of your app and simulate many run-time conditions. You can use a simulated SD card, drive a route virtually, disable sensors, send notifications, and test a different network speed.

Windows Phone Developer Power ToolsWindows Phone Developer Power Tools are three powerful testing and debugging tools for app developers packaged in a single user interface. Use the Power Tools to monitor your app's responsiveness and resource consumption and to debug its crashes.

Other Visual Studio toolsWindows Phone 8.1 adds support for many of the debugging, testing, and profiling features built into Visual Studio.

Existing Windows Phone 8 command-line tools – Isolated Storage Explorer, the deployment tool, and the phone registration tool – are still included in the installation. The Simulation Dashboard is not supported or updated for Windows Phone 8.1.

Backward compatibilityApps created to target Windows Phone 8 continue to function on Windows Phone 8.1 devices without being republished. The Windows Phone 8 developer documentation continues to be hosted on MSDN to support developers who target that platform. In addition, there are several new features introduced in Windows Phone 8.1 that can be used by Windows Phone 8 apps when they are running on Windows Phone 8.1 devices. 


sourcehttp://msdn.microsoft.com/en-us/library/windows/apps/dn632424.aspx