The Apple Worldwide Developer’s Conference saw everything from refreshed Macbook constituent (Air and Pro), to a new developer advertising of Elevation Celebrity, and iOS 6, with its computer of improvements. iOS 6 has been released to developers, time end-users module get their hands on the new operative method by the Denizen break.

The WWDC rumours we’d been chance ahead of the circumstance were blemish on, predicting most Apple’s announcements. Foreseen improvements to Apple’s movable operating system, iOS, in the new variant, were revealed at WWDC 2012, such as deeper Facebook integrations, iCloud updates like Joint Exposure Line albums, a new Maps app, and an enhanced Siri.

Apple says over 200 new features and improvements someone launches their way to iOS 6, and the complement did pass quite a few info. Apple’s deeper Facebook integrating translates into such features as pointed validate in and sign from the Notification Eye (as asymptomatic as Siri and Facebook-enabled apps), real-time updates to Facebook accumulation, from contacts to events, across all iOS devices. Users leave also be healthy to ‘Like’ App Stock and iTunes proportion, directly, whilst sightedness friend’s recommendations on the assonant platforms.

Siri give now employ on the New iPad as cured as iPhone 4S, and gets wider faculty living, including Country, Nation, Germanic and Nipponese, and adds validation for Country, Italian, Asian, Mandarin and Cantonese. Apple says the personalized helper is now optimized for 15 countries, with topical aggregation. Added improvements to Siri allow voice-based placard to Facebook and Sound without launch an app. Apple has advanced with virgin voice-based examine, enabling the two iOS devices to be used in a ‘Eyes Free’ modality, not requiring perception happening. This theoretically extends to a symbol of instrument succeed Apple’s certainty on Google and remaining gear parties in the employment department, providing vector-based maps with promised fluid graphics, turn-by-turn vox piloting, and reciprocal 3D maps with ‘Flyover’. Apple’s new Maps app also supports real-time reciprocation entropy, with term, and memorise way suggestions. Topical maps instrument also have Cry ratings for roughly 100 million businesses.

Otherwise improvements to iOS 6 countenance a new Passbook app – a new single-point programme for scanning and displaying passes. The Record app can demo real-time notifications, divided from automatically show passes on the ringlet protect, depending on abstraction or locating. iOS 6 also features new paternal controls in the work of Guided Make – locking the iOS gimmick on to a bingle app, throttle stir signaling, and writer.

New iOS 6 features including improvements to the Expedition raiseable application, such as iCloud tabs, offline measuring lists, exposure uploads and replete protection examine; keep for FaceTime calls over cancelled networks; a VIP Box; deciding to auto-message tell on telephone cancelling; callback reminders; and a Do Not Change alternative. Apple has also side a multitude of China-specific features, specified as developed text sign, and strengthener for services specified as Baidu, Sina Weibo, Youku and Tudou.

 

iOS6

iOS6

Reference – http://www.engadget.com/2012/06/11/apple-unveils-ios-6-at-wwdc/

 

Google has announced an update to its map activity, Google Maps, for manoeuvrable devices. The update v6.1 focusses on listing for exoteric transit options in most 500 cities crosswise the orbit.

 

Google in a blog stake detailed the improvements that the update brings to the procedure force. Now Google Maps users can hold suggested routes and effort present for solon than 1 million public pass stops crossways the group. Google instrument also give inside directions for work.

 

“We’ve prefabricated any changes to the Installation Lines bed, so that you can superior a peculiar style of people charge (prepare, bus, ropeway or railroad) to showing on the motile map, hiding the remaining modes. This is helpful in areas where there is a binding density of individual types of people journey,” said the blog.

 

Mitt: Metropolis map with all modes of exclusive journey shown; Right: Journeying Lines sheet in Tube property

 

Left: Mobile map with all modes of public transit shown; Right: Transit Lines layer in Subway mode

Left: Mobile map with all modes of public transit shown; Right: Transit Lines layer in Subway mode

Moreover, Google has updated the layout of rank pages to be many recyclable. Open it by tapping on the name of the position on your metropolis map.

Updated station pages show you departure times, lines serving the station and the distance to nearby stations.

Updated station pages show you departure times, lines serving the station and the distance to nearby stations.

Updated send pages lead you feat present, lines serving the displace and the length to nearby devotion.

 

Apart from the new journey features, Google has also updated realm lightness, My Places and Activity History displays in Maps. Users faculty now be fit to see borders of a part. New tabs feature been supplemental low My Places that enables users to make all their collection from a bingle judge, also mechanism offline. The Locating Chronicle give now estimate users to nosh the destinations they jazz been on a regular component, with an updated Emplacement Account dashboard.

 

Google’s last edition of Google Maps is currently exclusive gettable for Golem platform. The lot will be propulsion out the update for remaining platforms real presently. Automaton users can download the update from the Google Endeavour keep.

 

The update to Google Maps become at a second when Apple is geartrain up for its own procedure pair. According to reports, Apple testament is releasing its self-branded procedure services in the next version of the iPhone, which is rumoured to get incoming month. Late, Apple declared dropping built-in YouTube app from its IOS 6.

Reference – http://googleblog.blogspot.in/2012/08/google-maps-now-has-schedules-for-more.html#!/2012/08/google-maps-now-has-schedules-for-more.html

 

India has had its name of giving low-cost IT labor for long however the name could be in peril tells U.S. a study conducted by Cushman & Wakefield and Hurleypalmerflatt named ‘Data Centre Risk Index’ . The study evaluated “Data Centre Risk Index” i.e., the risks to international knowledge center facilities and international investment in business vital IT infrastructure.

In the survey, Asian country scored associate degree unsurprising second position within the most risk ridden knowledge Centre location among prime thirty countries, the last being Brazil. The center of world outsourcing over the past few years might not look therefore enticing anymore! This could ensue to India’s low score in “Ease of Business”, “Inflation”, “per capita GDP” and “Corporate Tax”. The recent grid collapse solely adds to such an occasional ranking of Asian country within the study.

Arvind Nandan, administrator, practice, India, Cushman & Wakefield says, “India and key Asian economies stay most popular locations for DCs and have witnessed a growth in demand attributable to numerous benefits. Asian country offers the {benefits} of price benefits and property of operations. We might expect the expansion to continue as this can be additionally as well as a rising domestic demand for IT services wherever net and mobile communication penetration remains moderate. Investment by overseas players continues showing confidence within the future potential of Asian country. At identical time it’s necessary to place in situ numerous initiatives for developing different areas like energy, bandwidth, rising business atmosphere, knowledge protection laws, etc., which might enhance the proposition for Asian country.”

More and additional firm’s area unit trying towards the Nordic nations to find their knowledge centers as they provide renewable sources of energy. Another excuse is also that the countries are blessed by Boreas with weather that is favorable for knowledge centers as they create down the cooling prices of the info centers.

The U.S. retains the highest position within the ranking because the lowest risk location to line up a knowledge center and UK ranks second as these data centers have the nice information measure, perform well in different tiers like tier one risk classes, and have the biggest proportion of their population finishing tertiary education.

The safest place in Asia to setup an information center is Hong Kong, the second being Asian nation, ranking seventh and thirteenth severally.

Stephen Whatling, international Service Director at Hurleypalmerflatt, said: “Indonesia, Asian country and Brazil area unit all thought-about growth markets, however with barriers to entry, regulated markets and high energy prices they are doing score poorly relative to the capable economic markets. Property is additionally a haul however as these markets still be invested with in and therefore the infrastructure becomes additional developed we might expect them to get on my feet the rankings.”

The Asian country government can ought to return up with higher policies and reforms to create India a profitable market once more for major IT firms. Allow us to wait and watch what the Asian country government will (rather let’s hope it will something) to revitalize the business vital IT infrastructure in India.

 

 

In this section we will have a look at how we can reuse resources, templates, xamls, custom elements and custom controls.

Resource System

The first way of making UI reusable is using the Resource System provided by WPF. But this approach cannot be used at all the places because it is not supported for UI elements. We can define UI elements in the resource but if we use it more than one place we will get an error as the resource system will refer to the same underline object. So this approach will be useful where we can reuse the objects itself. So this approach is perfect for Freezeable as the types which derive from freezable are shareable. For example if we have a logo which needs to be shown at multiple places then we can define it as a resource and reuse it.

*A freezable object has two states – frozen and unfrozen. When an object is frozen, it cannot be modified and it cannot even fires events but the unfrozen state, it works same as a normal object.

There is a trick which works in compiled xaml scenarios can be used to define reusable framework elements. We use the compiled XAML’s deferred loading to give each resource reference a new copy. As in compiled xaml the Resource Dictionaries are loaded on demand. This won’t work if this xaml is parsed at runtime.

Let’s see this in action. Add the following code to your window. The resource that we see here has x:Shared to false. When you are typing this xaml you will not find this appearing in intellisense . The reason is because Microsoft has hidden it and it might go away in the future versions. Using this False value will help us share the component because it specifies that the object should not be shared and each element using this should have its own copy. Normally what happens when we ask for a resource what WPF does is it creates an instance of it and keeps it in handy and when some other objects asks for it WPF provides the same object reference. But as we have turned off the sharing of the resource WPF will not keep the reference of the object in memory and when another object asks for this reference then WPF creates a new one and give it to the object. This won’t work for parsing xaml.

 

WPF Resource System

WPF Resource System

When we run this we will see that we have two buttons using the same resource. It would just work for simple static resources.

Templates

Templates are designed as a mechanism to reuse the trees of object that include user interface elements or behaviors. The event handlers that we define in the templates will be hooked to the object each time it is instantiated. Templates are usually declared as resources and it is a shared object. A template is just a factory and each time we use it creates a new copy and gives it the object. Templates are usually defined to work in a particular context like the ControlTemplate works to define the look of a particular control and a Data Template will work to display the data in the specified format. To use the template in a particular format we need to use the raw template. Let’s see this in action. Add the following code to your WPF window and you will see that we have specified a ControlTemplate in the Window.Resources. We have instantiated the ControlTemplate with the help of the Control Base class. As Control is the base for all Controls and it introduces the concept of Templates in the Controls and it’s not abstract. A control does not have any intrinsic behavior so we have used it as a way to host the template. It is not the perfect way of using the template though. As you can see we have specified that the controls should not act as a focus control. If we do not turn off the Focusable then each of these controls will have focus twice.

 

WPF Templates

WPF Templates

Another way of fixing this double focus issue is by using a DataTemplate and a ContentPresenter. Add the code as shown below to a Winow xaml.

 

WPF Templates

WPF Templates

The best place to use data templates is when the situation demands it such as DataBinding or ControlCustomization.

Xaml File Reuse

We can also reuse the xaml by separating it out to a different file and we can use Application.LoadComponent to load the compiled xaml resources. The Application.LoadComponent creates a new object by reparsing the xaml or baml every time it is called. After loading the component we need to add it to the UI tree. The root of the xaml file can be any type and we can package any sub tree this way.

We can also use a Frame or a NavigationWindow to load the xaml. It’s really straight forward to load   the xaml this way. All we need to do is point Frame directly to xaml file in the project and it will load a copy of the page. We can only point these to a xaml file whose root is a Page.

Xaml with Code Behind

In our application we can combine any xaml file with a code behind file. All we need to do is to provide the x:Class attribute which will define the code-behind class and we can use any WPF type as the root.

Let’s see this in action. Let’s create a reusable Grid with some behavior. Add the following xaml to a Page.

 

WPF Xaml + Code Behind

WPF Xaml + Code Behind

Now add the following code to the code behind of the GridComponent.

 

WPF Xaml + Code Behind

WPF Xaml + Code Behind

Now let’s try use this GridComponent which has a Button Click behavior,

 

WPF Xaml + Code Behind

WPF Xaml + Code Behind

Anytime we are defining classes with code behind, we are just creating partial classes and we can instantiate them with C# new operator or we can use xaml as shown above.

UserControl

UserControl is name of the reusable UI component which is built from other components. As we saw in the last section that we derived from a Grid to create a custom control, generally in WPF we derive from UserControl. You should know that UserControl does not do a lot. We can take an approach similar to user control with any UI element. The main reason of the existence of UserControl is to have a recognizable base class. The only problem with using Grid as the base class instead of the UserControl is that the .NET programmers will expect the Grid base class to provide the same functionality a Grid does and that might be really messy because the Grid will break the rule that the derived class provides the same functionality as the base class. As a matter of fact the UserControl also breaks the rule of derived class. The UserControl derives form Control but still it does not provide the functionality for a Template because there is no way to hook up the look of the UserControl with the code behind. User Controls are not lookless controls. UserControl is derived from ContentControl. It does that because whatever control you put inside UserControl xaml it displays that. This means if we set the content of the UserControl then the complete content of the UserControl will be replaced. So we should not try to set its template or Content.

Limitation – A class only gets to use xaml once in its inheritance chain. Although we can inherit from UserControl, we cannot use the xaml because the UserControl base class has already used it and same is true if the class derives from Window or Page. A class gets to use xaml with code behind only once and the base class has already done that then we cannot do it again. To understand this you will need to understand how Application.LoadComponent works. The way it hooks up xaml with code-behind is incompatible with inheritance. There are two things that need to be hooked up at xaml loading time.

  • Named elements must be placed in their corresponding fields.
  • Event handlers that specified its attributes must be attached.

Application.LoadComponent does this by using the interface IComponentConnector. The code behind class implements this. So when the derived class tries to implement the IComponentConnector then its implementation replaces the one that was done by the base class.

Runtime XAML Parsing

We can generate and parse xaml at runtime. For example we have an application that returns xml documents then we might have to run these through xslt which will generate the xaml and we would parse and run this xaml. This parsing can be done through the xaml reader class. We can do this by passing the xaml string or by passing xamlReader object and it will return an object with the root as the xaml tree and that tree will be defined as the xaml passed. The restriction in this mode is that events will work. Also we will need to call the FrameworkElement.FindNamed helper method to find any named components.

Custom Elements

Here are a few base classes that do not involve xaml:

  • Decorator – It is the base class for all the utility elements that contain a single child and provides some sort of service. The exact functionality of the decorators varies from a decorator to decorator. The border decorator provides the border around the child element whereas a viewbox applies a scale transform on the child so that the child takes all the space. A decorator and content control both host a child. The difference between them is that a Content Contol has some interactive behavior whereas a decorator does not.
  • Adorner – Adorners are visual elements that are attached to some other elements that always appear on top. As we can see in the image below that one of the grids is selected and all the resize, rotate, etc options available are all adorners. These adorners will be visible even when the object’s z-index in low and its not visible on the screen.

 

WPF Adorner

WPF Adorner

But an adorner decorator is the one which decides the bound of the adorner. So even when the element is sent back then also adorner is visible so you would think that an adorner is designed to be on the top at all times but when a panel comes above it as shown in the image below the adorner does not come above it. This is done with the help of an adorner decorator in the visual tree. S here an adorner decorator is defined as the parent of the design surface so that no adorner comes above it.

 

WPF Adorner

WPF Adorner

  • Panel – Panel is the base class for the WPF layout strategy type i.e. Grid, StackPanel,etc. If we want to write a custom layout we need to derive from Panel.
  • Shape – This is the base class to use when building any custom shape like a rectangle or ellipse. It provides Fill, Geometry cache, etc properties.
  • FrameworkElement – This is the base class to use when we are building a Code based user interface element and there is no other base class that suits our needs.

Custom Controls – This used when our UI elements has some distinctive behavior which is not provided by the controls available.

API Considerations

While building a custom control or a custom feature we need to consider the following things.

  • Properties – These are useful for components that are reusable from xaml as this is the API that does not require code and the functionality of the control will be accessible simply by setting properties. To use properties we need to use the WPF’s dependency property system so that the property supports Triggers, Animation, styling, data binding, notifications, etc.  So there might be properties that do not do a lot in code but are controlled by the templates.

 

  • Events – These allow code to be run when things happen in your code. These also allow triggers to be hooked up into xaml. Defining a custom event is pretty similar to defining a property. We need to register the event and store in a public static read only field.

 

We provide event accessor. The AddHandler and RemoveHandler methods are provided by the FrameworkElement base class.

 

We need to raise the event by creating a RoutedEventArgs and passing it into the FrameworkElement ReiseEvent method. RaiseEvent requires the event to be of type RoutedEventsArgs or derived from that.

 

We can add a class level event handler for the built in events.

  • Commands– These are really useful in controlling the behavior of the elements as any operations that can invoked by commands can be driven by xaml. We can hook up controls like menu item or a button with commands. Commands are really straight forward. We just need to create a Command of type RoutedUICommand and provide a name, display name and owning type. Commands are made available as public static read only fields.

 

In order for a command to do something we need to register a command Binding. As we want each and every instance of the class to handle the command we should use a class level command binding instead of the instance level binding as the class level binding is slightly more efficient. To register the command we need to pass the static command name and command owner details to the CommandManager.RegiterClass method.

 

  • Control Template – While writing a custom control we need to decide how its template will work. We should define the control by defining the idioms for the control liked the named parts. This tells what the control expects from its template. We can list parts we require by specifying the TemplatePart attribute. We need to declare the name of the part and the type it should be compatible with. Let’s see  this in action. Add a custom control to the project as shown in the image below.

 

WPF Custom Control

WPF Custom Control

Now let’s use the NamedParts idioms to specify what we want in the template.

 

WPF Custom Control

WPF Custom Control

The most important thing to do while working with templates is to override the OnApplyTemplate method as WPF will call this each time the control is given the template and this might happen multiple times. The first thing that we do here is check if the tenplate is not null and then we proceed to find the named part in this particular control. Then we cast it to the types of Shape. If the template named part is not null then we hook up a mouse down event handler and in this event handler we set the target fill property to green.

 

WPF Custom Control

WPF Custom Control

Now, Let’s use this custom control in our application

 

WPF Custom Control

WPF Custom Control

On MouseDown event the fill changes to green. So our handler works for the templates.

Themes

Most controls would want to have a default template. We generally do this by providing the compiled xaml resource by putting them in the themes folder. We should also provide generic.xaml  to provide the resources that might be needed when the resources specified by the user are not available. Also the assembly must declare the presence of these themes by using the Assembly Info attribute. This tells whether theme resources are present and whether generic resources are present. As we can see in the image below WPF added this information when we added the custom control.

 

WPF Themes

WPF Themes

WPF also added a Generic.xaml when we added the custom control and this contains a style for the custom control that we added.

 

WPF Themes

WPF Themes

Let’s add one more instance of the custom control without overriding the template and we will see something like below. The functionality of both of them is same but the appearance is different.

 

WPF Themes

WPF Themes

Designer Integration

We can integrate with design environments such as Visual Studio or Expression Blend. We can move all the general purpose design time code to a separate dll and we can follow the naming convention by adding .Design at the end of the class name. Or we can place the designer specific code in the dll with extensions .Expression.Design or .VisualStudio.Design in the end and if we install these dll so that they appear in the add reference panel then the designers weill be able to locate them.

We can put design time components in the toolbox for any design time environment. Visual Studio provide option to specify the Custom adorners or items in context menu or view or modify Object tree or property grid.

If we want use the design time dlls then the design time dll must include a implementation for IRegisterMetadata.

 

Any questions, comments or feedback are most welcome.

The code for this post can be found here.

 

In this section we will look WPF text formatting in layout services. We will have a look at text rendering feature, text layout services, text object model and text editing controls.

Rich Text

WPF uses ContentModel to present the text so WPF is does not just present the text as a plain string but allows you to take control and present whatever you want, so all the controls that use text are free to use WPF text formatting. As we can see in the image below we have used multiple fonts and color in the TextBlock inside a button. I know it looks ugly but the point is that this is the kind of capability WPF provides us with.

WPF Rich Text

WPF Rich Text

As we can see in the image above we have placed a textblock inside the button. TextBlock is your control if you want to a few letters or a few paragraphs. It supports Font Styles like FontSize, FontFamily, etc. It also offers block level formatting options. But default a TextBlock only runs a single line display but if you want to display paragraphs you need to turn on text wrapping. We can specify the TextAlignment. Till now you have seen TextBlock accepting the strings as the Text to display. That is done for the convenience for DataBinding, etc. We can provide content model to the text to provide formatting to the other part of the texts. We have individual properties which will be used to provide formatting to text sections. There is also Span which can be used to apply a format to the span of a text. We also nest these formatting like a span inside a span. As use can see that we have painted the text with LinearGradientBrush. It is evidently similar to html. Though it might look like HTML these are objects and blend well with .NET.

Class Hierarchy for WPF Text Model

Inline Text Elements

In the image below we can see the class hierarchy of the WPF Text Object Model. These are the Inline elements of the text like the short runs of text that are within the paragraph like a bold or underline. As we saw in the Core Elements section that the most of the WPF Elements derive from the FramworkUIELements but Text derive from the FrameworkContentElement. As we can see TextElement derives from FrameworkContentElement and provides properties like FontSize, FontFamily,etc. The properties in other WPF Controls provides aliases to these properties. If you go to the Control.FontSize property of a control and retrieve its DependencyObject then you will see that it derives from TextElement. Controls just provide an easy way to use these properties rather than using the cumbersome attached properties syntax. Controls do this by using the static Add Owner method of the dependency property which allows an element to declare the use of attached properties as a local property.

 

Inline class is the base the class for elements which are designed to use within a paragraph. As we can see that these elements which are designed to use in a paragraph and the most of them then further derive from Span. Span defines a children property and Span can acts a container and that is why we are able nest these elements in XAML. LineBreak lets you add line breaks between paragraphs. WPF does not consider these as paragraphs from Content Model point of view. And since Paragraph is not an inline element and so we cannot use it as the inline element. So LineBreak comes in handy and it helps to design stuff inline that looks like a paragraph. Run is an inline element which we always use but never write it. Confused? Actually Run element is the only one capable of holding a string The Span is a content model that support only inlines. Run is automatically generated when we add text strings. Let see this in action. You will see that the run elements are automatically generated by the xaml compiler when the types request it.

 

WPF Inline Text

WPF Inline Text

Block Text Elements

Blocks are paragraph level constructs like List, Tables, etc. Since these elements do not derive from inline we cannot put them into textblock so we need to place them into a FlowDocument that supports Blocks.

 

Document Viewer Controls

To display a flow document we need to use one of the DocumentViewerControls.

  • FLowDocumentScrollViewer – This displays content as continuous vertical scrolling. This one looks similar to a web browser page where we can place unlimited content and it will scroll vertically.

 

WPF FLowDocumentScrollViewer

WPF FLowDocumentScrollViewer

  • FlowDocumentPageViewer – This provides a paginating view. You can see it in lot of online reader like msdn reader. This will size the content to page according to the reading area available and font size so that no scrolling is required and it uses pagination for the documents that not fit one page.

 

WPF FLowDocumentPageViewer

WPF FLowDocumentPageViewer

  • FlowDocumentReader – This lets the user decide as to which FlowDocument style to use. This is similar to what we will get wahen we display a flow document inside a content control.

Paragraph

Paragraph is the simplest block type. It is just a collection of inlines and so we can fill it up with text or marked up formatted text. Since paragraph support inline contents it will wrap its content into run elements impliclitly.

 

Section

Section is another block type. As the block has no intrinsic appearance of its own. The purpose of a block is to let us group several other blocks together and then we can set the text formatting properties on the entire block any text formatting applied to a section will imply on all the blocks of the entire section.

 

List

List block type makes it easier to display bulleted and numbered list. WPF provides just one list that does it all. The MarkerStyle property of the list will specify whether we want bullets or numbers. You can specify the numbers, letters or bullets. We can use only inbuilt bullets as there is no way to define the custom bullet types.

 

Table

The table block element lets us build the table of texts. This may seem similar to Grid but the Grid derives form FramworkElemet and Table derives from FramworkContentElement as it is a text element. The table understands the text layout roots and this enables the table for doing what the grid cannot. Like a table can span multiple pages if it cannot fit one page. Also unlike the grid we do not need to tell the table upfront as to how many columns are needed. It generates them as per the content. The advantage of grid over table is that we can put multiple elements in one cell which is not possible in a table. We still can have nested elements inside a table cell though.

Figures and Floaters

Other inline types are Figures and Floaters. They cannot be used inside a TextBlock though. These can be use only in a FlowDocument. These let us place the content that is out of the main flow of the document like images, tables, etc. They support nested items of content and the main text will flow around them. These elements provide as an anchor point for content out of the flow of the document.

Floater – It is the simple of the two and we can provide the alignment of the element.

Figure – This is more flexible. It’s designed for paginated views. We can the content to appear at the top of the page, half of the width of the page or span a couple of columns.

Integrating a UIElement in a FlowDocument

We can do that by using the following:

  • BlockUIContainer
  • InlineUIContainer

RichTextBox

This is like the textbox but uses the FlowDocument as its internal representation. So it uses the TextObjectModel we just explored. It can also import or export the rich text format through the clipboard.

Any questions, comments or feedback are most welcome.

The code for this post can be found here.