Monthly Archives: June 2013

Creating a Group Style

An ItemsControl can work with grouped data in two ways. It can:

  • Bind to grouped data, and display the items from all the groups, without displaying the items in specific groups.
  • Bind to the groups, so that the control displays the groups and the items within each specific group.

Of course, there are different ways to group the data, as well. The data source might be a list of groups, where each group contains the items in that group.

The data source might also be a grouped data structure that you get by using a grouped LINQ query. In this case, there isn’t a distinct name for the subgrouping, so you must rely on the behavior of the ItemsControl to manage the display of the groupings.

As you’ve seen, by default, even if you bind to a grouped data source, the ItemsControl displays no grouping information. In order to add this behavior, you must explicitly specify how you want the ItemsControl to display its grouped data. To make that happen, you must specify the GroupStyle property of the ItemsControl, and provide a GroupStyle element that describes how the grouping should work, visually. In this article, we’ll take a deeper look into creating a Group Style.

Creating a Group Style

The GroupStyle element generally specifies a header template for each group within the grouped data source. You can modify the arrangement of items within the group by setting the Panel property of the GroupStyle object. You may want to specify how the group itself looks, and to do that, modify the GroupStyle’s ContainerStyle property. It’s in this property that you would specify a border, or a specific font. If you want to hide empty groups, make sure you set the GroupStyle’s HidesIfEmpty property to True.

In the sample that you’ll examine, you’ll find markup like that shown in the Figure below, which shows the markup for a ListView bound to grouped data, with all the child elements collapsed. Note the ListView.GroupStyle element, which contains a GroupStyle element that defines the group style. The GroupStyle element contains elements that describe the HeaderTemplate, Panel, and ContainerStyle properties of the GroupStyle.

Ch10_BlogThe sample’s ListView bound to grouped data

The HeaderTemplate property contains information about the header for each group, as shown in the Figure below. This header displays the Key property of the group, with black text on a gray background.

The HeaderTemplate element describes the header for each group

The Panel property (see the Figure below) defines the control that forms the group content. In this case, the group content is contained in a VariableSizedWrapGrip whose orientation is horizontal.

The Panel property defines the control that displays each group’s content

The ContainerStyle property defines the style for the group container, as shown in the Figure below. In this example, the group container has a 2-pixel-wide dark gray border, and margin of 3 pixels all the way around.

The GroupStyle property

Displaying grouped animal data, using the animal type (Domestic, Exotic,Farm, Wildlife) as the grouping field, looks like the Figure below.

windows 8 The grouped data


ldn-expertkgetzThis post is an excerpt from the online courseware for ourWindows 8 Using XAML: Views, Resources, and Toastscourse written by expert Ken Getz.

Ken Getz is a Visual Studio expert with over 25 years of experience as a successful developer and consultant. He is a nationally recognized author and speaker, as well as a featured instructor for LearnNowOnline.

Windows 8 Using XAML: ItemsControl Styles

As with every other control you use in Windows 8 applications, both the ListView and GridView controls (that is, both ItemsControls) are based on control templates that determine the manner in which these controls appear.

For example, Microsoft supplies default styles that affect the way each ItemsControl appears. They supply two different sets of styles, one for the Light theme, and one for the default Dark theme. This concept applies to every XAML control—that is, every XAML control is based on a template that defines all the styles for various parts of the control.

It’s crucial to investigate the control styles for ItemsControls, because (for reasons that aren’t particularly clear) the default styles for the Light theme simply don’t work with ItemsControls! As you’ll see, the selected item in an ItemsControl, when you use the Light theme, appears with a dark purple background and black text. This makes any text in the item unreadable. Luckily, it’s easy to override the default styles. >/p>

All of the styles that affect the display of every XAML control are documented, including ListView and GridView. Microsoft has provided, as part of its developer documentation, a list of all of the control templates and their default styles, as well as instructions on which styles to override to change the look of each control. All you need to do is override any of the styles in your application’s App.xaml file (or in a resource library referenced from App.xaml).

You can find the styles for ListView controls (not the ListView items, but the control itself) here:

http://go.appdev.com/?id=8AFA

You can find the styles for GridView controls (not the GridView items, but the control itself) here:

http://go.appdev.com/?id=8AFB

When you browse to either of these pages, you’ll find a list of styles that you can override, and the entire control template. The Figure below shows the available styles you can override for the ListView control. These styles apply only to group headers.

Item styles are more interesting, because you can override them immediately to modify the look of an ItemsControl. ListViewItem styles, pertinent to both the ListView and GridView controls, are documented here:

http://go.appdev.com/?id=8AFC

The documented ListViewItem styles, shown in the Figure below, allow you to override any part of the ListView items in your applications.

ListViewItem styles

There is, unfortunately, no real documentation on how each style affects the display of the ListViewItem, so it’s up to you to experiment with the various styles until you find the one that changes the attribute that you care about. In any case, to modify the behavior of a ListView Item, copy the necessary style into App.xaml and modify its value, effectively overriding the default behavior of the style.

Note that the documentation includes separate styles for Light and Dark themes. The items in the documentation describe the default settings. You can override any individual style (or group of styles) to modify the look of the control.

ldn-expertkgetzThis post is an excerpt from the online courseware for our Windows 8 Using XAML: Views, Resources, and Toasts course written by expert Ken Getz.

Ken Getz is a Visual Studio expert with over 25 years of experience as a successful developer and consultant. He is a nationally recognized author and speaker, as well as a featured instructor for LearnNowOnline.

SQL Security Fundamentals: Changing the Execution

2.0-bigsqllogo

 

You don’t always want the caller’s permissions to be used to validate permissions in a broken ownership chain. Sometimes you want to execute the code as though it was being executed by another user entirely, by using that other user’s permissions to validate permissions on all of the accessed objects.

This is called switching the execution context of the code. This lets you take advantage of SQL Server’s granular permissions, keeping tight control over the permissions to underlying objects, while giving various users the ability to execute the code.

In SQL Server, when you define any kind of user-defined functions (except inline table-valued functions), stored procedures, and data manipulation triggers, you can use the EXECUTE AS clause as part of the definition of the code to run the code under the security context of the specified user.

Four EXECUTE AS options are available:

  • EXECUTE AS CALLER: The default for backward compatibility. The code executes in the context of the caller of the code, who must have permissions both to execute the code and to access underlying objects. The actual behavior depends on whether the ownership chain is broken or unbroken.
  • EXECUTE AS= ‘username’ and EXECUTE AS = ‘loginname’: The code executes in the context of the specified user or login, so that the user must have permissions on underlying objects. In this case, the caller must either:
    • Have execute permission on the code.
    • Be a sysadmin or db_owner, or have CONTROL SERVER >permissions on the server or the database, or have impersonate permission for the username.>
  • EXECUTE AS SELF: A shortcut notation for the current user who is creating the procedure. This is equivalent to EXECUTE AS USER = [myUserName]. The SQL Server catalog stores the actual user ID of the person who writes the code.
  • EXECUTE AS OWNER: Another variation of execution under the security context of a specific user, in this case the owner of the code at the time of execution. If the owner changes after the code is created in the database, it is the current owner when the code executes.

TIP: Any time the security context of the code changes through EXECUTE AS, the creator of the code must have the IMPERSONATE permission for the user specified in the clause. You don’t ever need to have this permission to impersonate yourself, however, such as for EXECUTE AS SELF.


ldn-expertdkielyThis post is an excerpt from the online courseware for our SQL Server 2012: Security Fundamentals
course written by expert Don Kiely.

Don Kiely is a featured instructor on many of our SQL Server and Visual Studio courses. He is a nationally recognized author, instructor and consultant who travels the country sharing his expertise in SQL Server and security.

Taking a Deeper Look at New Changes in the SharePoint Platform

en-usRecently, we talked about the new changes to Microsoft SharePoint and how that’s creating demand for experts in this wildly popular platform. Today we’d like to briefly look at some of these changes, many of which have been summarized by Mark Kashman, a SharePoint senior product manager, here.

(In fact, for those looking for SharePoint related work, the aforementioned article is a must-read. That and our SharePoint tutorial, of course.)

OK, so about those changes.

For starters, SharePoint will be integrated with Yammer, a social media application. The user interface, meanwhile, will include touch capabilities and asynchronous calls. Subscribers can share documents and files to users both inside and outside their company with a new “Guest Link” feature. And new “on-hover” feature lets users view contact information or a document preview for a document search.

This is all, of course, the tip of the iceberg. And it’s precisely because of that – new capabilities, new functionality, new complexity – that companies all over will be looking for SharePoint ninjas.

7f6b1efb-94c0-4c58-b924-1d9cf41c59dc

 

 

Thousands of developers worldwide use LearnNowOnline to gain the technical skills they need to succeed on the job and advance their career.

Windows 8: Adding Items from a File System

windowslivewriter_customplacementwithinanitemscontrolinwpf_ee53_image_6

In order to take full advantage of an ItemsControl, you must be able to bind it to an existing collection of data. Most of the time, you won’t add items to an ItemsControl individually. Instead, you’ll most likely bind the ItemsControl to some sort of data source. Any data that can be stored and retrieved as a list or array of items is fair game for display in an ItemsControl.

Data in an ItemsControl can come from any collection of data, such as an inmemory data structure, the results of calling a Web service, or data retrieved from a database. It’s really simple to bind an ItemsControl to any collection of data in memory: You set the ItemsSource property to the collection of data, and the ItemsControl does the rest of the work.

Adding Items from File System

What if you wanted to bind ItemsControl to some real data? The simplest place to get “real” data is from the file system, and you can easily bind an ItemsControl to information from the file system, with a little effort.

Although it’s not difficult to bind to information from the file system, it does require a little more effort than you might expect. In order to retrieve any information, you’ll need to create an instance of the FileInformationFactory class, which provides several use methods:

  • GetFilesAsync: Retrieves a collection of FileInformation objects. The method does its work asynchronously, but returns the full file list.
  • GetVirtualizedFilesVector: Retrieves a virtualized vector of IStorageInformation objects. By virtualizing its results, this method makes it possible for an ItemsControl to effectively display a huge amount of data. Scrolling through the control causes the data source to retrieve more data.
  • GetVirtualizedFoldersVector: Works like the GetVirtualizedFilesVector method, but retrieves only folderinformation.
  • GetVirtualizedItemsVector: Works like the GetVirtualizedFilesVector method, but retrieves both file and folder information.

NOTE: The IStorageInformation class acts as a base class for information about files and folders.

In order to bind to data retrieved from the file system, you will also need to follow these steps:

  1. Optionally, create a QueryOptions object whose properties describe the requested sort order and filtering. If you don’t specify a QueryOptions instance, you will retrieve data in natural order including all the filesand/or folders.
  2. Retrieve a reference to a specific folder, or use a known folder (an item in the KnownFolders class).
  3. Create an instance of the FileQuery class, calling the CreateFileQuery method of a storage folder, optionally supplying the QueryOptions object you created previously.
  4. Create an instance of the FileInformationFactory class, passing the FileQuery you created previously, and optionally, other parameters.
  5. Set the ItemsSource property of an ItemsControl to the results of calling one of the FileInformationFactory’s methods, such as GetVirtualizedFilesVector.


ldn-expertkgetzT
his post is an excerpt from the online courseware for our Windows 8 Using XAML: Views, Resources, and Toasts course written by expert Ken Getz.

Ken Getz is a Visual Studio expert with over 25 years of experience as a successful developer and consultant. He is a nationally recognized author and speaker, as well as a featured instructor for LearnNowOnline.

Microsoft Announces Updates to SharePoint, Underscoring the Need for SharePoint Experts

en-usSharePoint is one of the most important – if not the most important – collaboration tools in the world of business. So if you’re looking to build a career for yourself, we suggest following the money, which in this case, is SharePoint.

A majority of businesses still run on Windows and, by extension, most of them use Microsoft’s SharePoint platform. It allows users to store documents, collaborate on the cloud, and interface with other back-end systems.

And just last month, Microsoft announced a whole host of new features and improvements to its SharePoint platform. For example, the company says users can expect improved performance, a more intuitive user interface, and optimized user controls.

Someone, of course, has to manage these complex SharePoint deployments, which is why SharePoint-related jobs are in demand. Our SharePoint tutorial will help you simply and effectively master this platform, and boost your resume in the process.

Thumbnail for 628

 

Thousands of developers worldwide use LearnNowOnline to gain the technical skills they need to succeed on the job and advance their career.

 

 

Windows 8 Using XAML: Choosing a ListView or GridView Control

Windows 8 ListView and GridView controls both allow you to display data, but they display their collections of data differently. The following article takes a look at both controls and how they are used.

Choosing a ListView or GridView

In order to display multiple data items, you can select the ListView or GridView control. Both controls display collections of data, making it easy to present items from a list, or any other bound data source. Both controls provide similar functionality, although they display their data slightly differently. Both controls derive from the base ItemsControl parent class, and both inherit the functionality of the base control. Because both controls inherit from the same base class, they share a large number of properties. As a matter of fact, the controls are so similar, they’re often both referred to using the name ItemsControl (the base class), rather than saying “ListView and GridView controls”.

TIP: To be honest, the ListView and GridView controls are so similar, you can think of them as a single control. The major difference between the two is the manner in which they lay out their items, and it’s easy to change the layout so each control emulates the other.

The ListView control displays its data stacked vertically, much like a standard list box. Use this control to display an ordered list of data, like a list of email messages, a list of contacts, or search results. It’s also useful in master-detail layout scenarios—you can display the list of master items in a ListView control, and the details in some other kind of control. You can control every aspect of the layout of data in this control, including how each data item appears in the list, using templates.

The GridView control displays its data stacked horizontally in rows (although you can alter this behavior and have it displayed in columns first, as well). You use this control when you need more space for rich visualization of each item to be displayed. As with the ListView control, you can use templates to control the layout of each item, displaying the data in any manner you need.

There are several ways to display data in an ItemsControl. You can:

  • Add items directly to the Items collection property, in XAML or in code.
  • Bind the ItemsSource property to a data source.

Applications often use both a ListView and a GridView control bound to the same set of data, so you can alter the view based on the current screen layout. For example, you might use a GridView control in full-screen layout, but a ListView when in Snapped layout. The first Figure below shows a sample application using the GridView control, and the second Figure below shows the same application, in Snapped view. The trick here is to show and hide the two controls, based on the current layout.

using a GridView control

using a ListView control


Thumbnail for 559T
his post is an excerpt from the online courseware for our Windows 8 Using XAML: Views, Resources, and Toasts course written by expert Ken Getz.

Ken Getz is a Visual Studio expert with over 25 years of experience as a successful developer and consultant. He is a nationally recognized author and speaker, as well as a featured instructor for LearnNowOnline.

It is the Best of Times and it is the Worst of Times for Programmers

screen shot 2013-03-05 at 1.07.11 pm

Across the past six years, the US economy was mired in a recession. Yet throughout it all, there was one bright spot: the IT and programming job market. It seemed as if no matter how bad things got in the economy as a whole, there was always demand for IT skills due to a lack of supply.

And while the IT job market remains strong, it continually puts workers in a good news/bad news situation. The good news, of course, is that there are plentiful jobs, especially when compared to other segments of the economy. The bad news is that the competition is so fierce, the path of change so great, that workers can’t be complacent.

If their skills decay or if they remain idle for even six months, there will inevitably be other programmers – both in the US and abroad – who’d be happy to fill the void. The bottom line? Don’t be complacent. Continue to grow and learn. Expand your skills by taking a Java tutorial video, MVC tutorial, or a jQuery tutorial!

Thousands of developers worldwide use LearnNowOnline to gain the technical skills they need to succeed on the job and advance their career.

Does Google Prefer C/C++ or Java Programmers?

Java-vs-C

 

Any job hunter will tell you that while it’s important to have experience, a great resume, and a strong work ethic, it’s also equally important to do your homework regarding the company you’re interviewing for.

This can mean reading up on their financial situation in the Wall Street Journal, downloading annual reports, and understanding the firm’s strategies for future growth. And in the programming world this means understanding what languages the company is known for.

For example, there is an ongoing argument within the programming culture of Google: what language does the company prefer, C++ or Java? This article in Forbes addresses the question and the answer is: neither. What recruiters care most about is experience, a willingness to learn, and ability to think creatively.

So if you’re an expert in Java, odds are Google will want to talk with you. And our Java tutorial video can help you get there.

Thousands of developers worldwide use LearnNowOnline to gain the technical skills they need to succeed on the job and advance their career.

SQL 2012 Default Schemas for Users

2.0-bigsqllogoSQL Server doesn’t automatically create a schema with the same name as the user when you create a user. Instead you have to explicitly create a schema, assign ownership to a user, then create and add objects to that schema. You can (and usually should) assign a default schema to a user so that all objects the user creates—and doesn’t explicitly assign to another schema—become part of the default schema.

The following code shows how this works. After creating the DefaultSchema database and changing the database context to it, the code creates the login carol, maps it to the user carol in the database, and grants it the ability to create tables. It then changes the execution context to the new user carol.

 

The code next attempts to create a new table1. But when the code created carol it didn’t assign a default schema. SQL Server attempts to use the dbo schema, which is the default fallback schema. But Carol doesn’t have ownership rights in the database so she can’t create objects in the dbo schema.

Since carol doesn’t have the needed permissions the CREATE TABLE statement fails with this error message. In this case the problem of the two suggested is that carol doesn’t have permissions.

After reverting to the original admin login that started this session, the code creates a schema and gives ownership to user carol. You’ll see the AUTHORIZATION clause a lot in SQL Server because it lets you assign ownership in the same statement that creates or alters an object.

The code then once again changes the execution context to carol and attempts again to create table1. But, damn, it fails again! The problem now is that just because a user owns a schema doesn’t mean that it’s the user’s default schema. A user could own hundreds of schemas and SQL Server shouldn’t be responsible for picking one to be the default. But what does finally work is creating the table to be explicitly contained within the schema. The following statement explicitly creates table1 in the carolSchema, which finally works.

Success at last!!!

Thumbnail for 566

This post is an excerpt from the online courseware for our SQL Server 2012: Security Fundamentals course written by expert Don Kiely.

Don Kiely is a featured instructor on many of our SQL Server and Visual Studio courses. He is a nationally recognized author, instructor and consultant who travels the country sharing his expertise in SQL Server and security.