Making a Carousel Number Picker for Windows 8 Store Application

Alright, content will be basically the same with a previous blog, but with screenshots this time J

So you want to create a nifty and rockin control for a Windows 8 Store application to choose a number. There are a few reasons to do this and not a textbox. First you want to limit the entries to only numbers. Second, you want it to give your app’s user a nice experience. Something like this:

So here goes:

Fire up Visual Studio and create a new Windows 8 Store application

Then in mainpage.xaml, drop in a combobox and add a carouselpanel control inside it, you should have xaml that might look like this:

<Grid Background=”{StaticResource ApplicationPageBackgroundThemeBrush}”>


<ComboBox x:Name=”myCarousel” Height=”100″ Width=”100″>


<ItemsPanelTemplate>


<CarouselPanel/>


</ItemsPanelTemplate>


</ComboBox>


</Grid>

In case you are the drag and drop type of guy, you won’t be able to see the CarouselPanel control in the toolbox. So you should type it in ;)

Then what you will need to do is to populate the list. You can choose whatever way you want but for this sample I will populate it in code.

Nothing fancy. Then run this and see what it looks like. Weird right? So let’s add a little formatting J

So you should have something like this in your xaml

<Grid Background=”{StaticResource ApplicationPageBackgroundThemeBrush}”>


<ComboBox x:Name=”myCarousel”
Background=”Transparent” Height=”50″ Width=”50″>


<ItemsControl.ItemsPanel>


<ItemsPanelTemplate>


<CarouselPanel />


</ItemsPanelTemplate>


</ItemsControl.ItemsPanel>


</ComboBox>


</Grid>

If you run and use this you will see that it does open up a control that displays the numbers

But what will mess you up is the fact that if you choose a number, it will be behind the Combobox’s button!

Here I have encircled what remains (or what is visible) of the number 8 when I chose it.

So what do you do now?

Solution is to remove the Combobox’s dropdown button. The search term “How to remove or hide combobox dropdown button” might work fine at this point, or just read on.

What we want to do now, is to take the combobox control apart and remove that button. Wait, before you fire up blend, please allow me to stop you, I will use Visual Studio for this.

A nice addition to Visual Studio is the ability to edit the template of a xaml control, much like the way you can do it in blend.

You right-click the control you want to edit the template of and chose edit

I chose to Edit a Copy

And I also chose to place the definition in the Resource dictionary, and to apply the style only to this textbox.

Why?

  1. Place it in a common place like StandardStyles.xaml, away from your current page’s xaml file. As template styles tend to be in the form of huge xaml codeblocks.
  2. I didn’t apply it to all, as it would have made ALL comboboxes devoid of a button.

And now to edit the style, but read it first!

Here we see that a combobox has items inside a grid with 2 columns. One is explicitly sized at 32 units, and the other is sized to adjust (*)

Solution to the problem, I change the size of the column where the button is to zero.

Save and run it again and you will no longer see the button, and be able to see the number you choose.

Kinda looks weird so we set the alignments to center the displayed number by changing the property of the ContentPresenter, still in the combobox style

 

<ContentPresenter x:Name=”ContentPresenter” HorizontalAlignment=”Center” Margin=”{TemplateBinding Padding}” VerticalAlignment=”{TemplateBinding VerticalContentAlignment}”/>

 

And you will have:

I would say that is centered quite nicely.

And with all that done, you now have a control that shows a set of numbers in a very nice UX. J

Enjoy!

 

 

 

 

 

Posted in Computers and Internet | 4 Comments

TFSPreview Connection Problem

If you fall into the situation where TFSPreview tells you you don’t have the proper credentials to connect, but you can connect using IE, the quick solution is to clear the browsing history of IE including saved passwords. :)

Posted in Computers and Internet | Tagged | Leave a comment

How to make a Carousel control for Windows 8 using C#

The first time I saw this control I was amazed. Really slick UX, I told myself.

So I set out to use it. But.. can’t find it in the toolbox of VS2012.. such sadness and grief. So I go and research some more, and found that it was called a CarouselPanel. Nice!

Had some trouble getting it to work, specially on the UI. So to save you the trouble, here is how it goes:

So, open up visual studio and create a new store app..

Then add a combobox to it and modify the xaml to look like this:

<ComboBox x:Name=”CarouselContainer” Background=”Transparent” Height=”50″ Width=”50″
ScrollViewer.IsVerticalScrollChainingEnabled=”True”
ScrollViewer.VerticalScrollBarVisibility=”Hidden”>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<CarouselPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ComboBox>

Aight, that, you can populate any way you want. Either through C# or xaml, whatever floats your boat.

Then using Visual Studio, while in design view.. do the following:

1. Rightclick the combobox

2. In the appearing popup, highlight Edit Template. this will trigger another panel where

3. you click Edit a Copy. This will open up a dialog. It will ask you for a name, remember it. You can also choose to apply whatever styling you will be creating to All comboboxes or just the one you are creating.

This “template” thingie can be viewed as the styling of the control. So in essence, what you will be doing is taking the combobox apart and modifying it to look like what you want.

4. So, what you just did results in VS adding a huge chunk of code showing you how the combobox is drawn. (in a nutshell) and you will need to observe some stuff. If you can’t find it, it will be here

<Page.Resources>
<Style x:Key=”ComboBoxStyle1″ TargetType=”ComboBox”>

Looks logical right? It is a stlye called ComboBoxStyle1 that applies to a control of type ComboBox.

So sniff around a bit, click on the combobox and see how the Xaml shows that it is actually composed of a Grid with two columns. The column on the left holds the stuff that you will bind to your combobox, and the column on the right holds that button with a dropdown arrow (which is actually a glyph).

<Setter Property=”Template”>
<Setter.Value>
<ControlTemplate TargetType=”ComboBox”>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”*”/>
<ColumnDefinition Width=”32″/>
</Grid.ColumnDefinitions>

Next task is to determine how to remove the dropdown arrow from the combobox. Hey, it will be a store application UI so I want to remove that, and like I said in the first sentence, I want to copy a control that I saw on my phone.

5. Set the column that holds the button to Width=0. This will hide the button. Don’t worry about re sizing the column on the left, it’s width is defined as a star, so it will automatically widen to take all available space.

your resulting xaml will be

<Grid.ColumnDefinitions>
<ColumnDefinition Width=”*”/>
<ColumnDefinition Width=”0″/>
</Grid.ColumnDefinitions>

And with that, all you need to do next is to set the vertical and horizontal alignment of the ContentPresenter to Center.

You can bind or populate this any way is most comfortable to you. And you can still hook the selected*.* events to their respective triggers.

 

Enjoy!

 

 

 

Posted in Computers and Internet | 2 Comments

How to use Windows Azure Profiling Tools in Visual Studio

Just recently, I have been looking for a tool to profile my Windows Azure application when it runs on Azure. Yeah most browsers have that F12 dev tools, but they just won’t cut it for what I want. What I didn’t know, is that I didn’t look very far. As it so happens, the Windows Azure SDK includes a profiler that will profile your app (including code) when it runs on Windows Azure.

Was a bit hesitant so I decided to test it myself.

Steps would be:

  1. Create an azure worker role with two functions, one is okay, and the other is really bad (performance hog)
  2. Deploy it and have it profiled
  3. Hopefully the profiler will be able to identify which function is better, or which one needs improvement

Sounds sensible enough J

So I fire up Visual Studio and create a worker role.

So, what to put.. friend of mine Jon Limjap pointed me here and here is what I have now:

///
<summary>


/// Function I got from Stackoverflow


///
</summary>


///
<param name=”stringLength”></param>


///
<returns></returns>


private
string RandomStringGood(int size)

{

System.Text.StringBuilder builder = new
StringBuilder();


Random random = new
Random();


char ch;


for (int i = 0; i < size; i++)

{

ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));

builder.Append(ch);

}

 


return builder.ToString();

}


///
<summary>


/// modified it to be a bad function (my specialty hahaha)


///
</summary>


///
<param name=”size”></param>


///
<returns></returns>


private
string RandomStringBad(int size)

{


String builder = string.Empty;


Random random = new
Random();


char ch;


for (int i = 0; i < size; i++)

{

ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));

builder += ch;

}

 


return builder.ToString();

}

 

Then I call them

public
override
void Run()

{


// This is a sample worker implementation. Replace with your logic.


Trace.WriteLine(“$projectname$ entry point called”, “Information”);

 


while (true)

{

RandomStringBad(1);

RandomStringGood(1);


Thread.Sleep(10000);


Trace.WriteLine(“Working”, “Information”);

}

}

 

Short, simple and should do the job (fingers crossed)

So, then I use the profiling tool.. I deploy this to my Azure Subscription using Visual Studio

With these settings

I checked Enable Profiling then published it.

Some waiting involved..

Took while but when it is ready..

You can start profiling the workerrole

Again some waiting

Then I saw something that caught my attention

So I guess there is something that will need to be done with the symbols. But my test app is just a barebones app so I guess there is no need to worry about that just now.

I tried visiting the browser version of the Azure management portal.. and it showed activity

Annndddddd… here are the results!

The profiler indicates that RandomStringBad uses more resources than RandomStringGood!

And clicking on that item on the list takes me to the code

So I guess it works!

Posted in Computers and Internet | 3 Comments

Creating and Opening a Windows Azure Website

Microsoft announced the addition of the capability to create new websites straight off the Windows Azure portal. This is a great development but was not able to try it out immediately.

So, late as it is, here goes my attempt.

Logging on to the new portal, you will notice the “New” link..

Just hit that, and

I go the way of creating a new website based on a template.

There are several templates on line, I choose Orchard as it is close to my heart J

 

It asks me for a name, fair enough

 

Then I finish it.

It takes several minutes to deploy. But once you have it started, you have an Orchard CMS up and running on the cloud!

 

Now all is well and good, I try it out by clicking the url (or clicking the “Browse” button at the lower part of the page).. so that brings me to my brand spanking new Orchard powered CMS.

Configuring, editing and using the CMS will be the same is if it was hosted somewhere else. Nothing fancy to learn

Then you will have your 100% running Orchard CMS Website in minutes!

Of course complete with the dashboard

This blog will not include HOW to maintain an Orchard Website, that can be found in Orchard’s own website.

I was asked, what to do if one wants to download an offline copy of the website from windows azure to edit in his/her machine. Well the new Azure supports FTP and GIT, but an easy way is to find the “WebMatrix” button at the bottom of the page and clicking it. That will either download a fresh install of webmatrix (if not yet done) or fire up an instance of WebMatrix, already connected to your existing Orchard app on Azure.

It might take a few minutes depending on your connection speed.

But after that, it will start downloading all the needed files to your machine.

And afterwards, you have a working local copy of your Orchard powered CMS site!

So there it is! Creating an Orchard CMS through the Windows Azure Portal.

Posted in Computers and Internet | 2 Comments

Migrating a Data Centric Application to Windows Azure

My last blog entry was to illustrate some concerns that I have encountered when one is to develop an application to Windows Azure. So that comes as a bit of an oversight. I was looking at a world where there are no existing applications. So I backtracked a bit and will need to deliver a separate blog for Migrating or converting an existing web application to Windows Azure. Because 99% of the web applications out there are of course already existing.

But before we dive into that, I believe it will only be prudent to first give a definition of what an application built or migrated to Windows Azure should look like; and to define the scope of what a migration is.

First, the scope. Migration, as defined is the movement from one place to another. Not coexistence. As simple as that, we define what migration is. The existing web application will be MOVED from one location to another, with no turning back.

Then we define what is an application built for Windows Azure. It is very often that we hear people refer to an application on Windows Azure as a “Cloud Application”. Which is fair enough, as Windows Azure is, Microsoft’s cloud platform service. But I must state clearly, that not all applications running on Windows Azure were built for Windows Azure, hence, I would not consider them as cloud applications.

A cloud application, is one that was engineered and built in such a way that it will not run on any other platform other than the cloud. It will also take advantage of, and leverage everything that the cloud has to offer, such as Scaling, Multi-tenancy, CDNs, blob storage etc. If the application is not built as such, I will not call that said application as a Cloud Application or an application built for Windows Azure.

Simply put, an application must be deployed to Windows Azure, use the services offered (like Web Roles, Worker Roles, Cloud Storage etc) in the proper way, to be considered as a cloud application.

As I was writing this blog entry, I stumbled upon a webpage that illustrates everything I want to illustrate and more. J

So here it is.

Posted in Computers and Internet | Leave a comment

How to develop an application for Windows Azure – Part 1

 

If you are a Web App developer and tasked to either redesign or develop an application that will be deployed (not hosted) on Windows Azure, what are the things that you need to look out for? There are several of course, and in this series of blog entries, I will try to illustrate some key areas that you might want to take a look at first.

 

But before you do anything, I feel we must clear up a few things.

 

  • First, is a definition of what Windows Azure is (and cloud computing in general) and the general ‘attitude’ or mindset that you need to have during design and development.
  • Then we will need to look at how you would want to approach Software Development for the Cloud.
  • Also, we will need to have a good grasp on what makes up Windows Azure, its features, services etc. for you to be able to leverage on each and design a good cloud application.

 

So first let us define Windows Azure.

 

There are tons of definitions out there that you can search on the web. And I will try to give a definition, from a developer’s point of view.

 

Windows Azure, can be defined as an Operating System on the Cloud. Read again, an operating system on the cloud; NOT the operating system of the cloud. I have heard a few who thinks azure is the operating system of Microsoft’s datacenters; which of course, is as far, or as near to the truth as one’s imagination.

 

If you are a developer, you would want to approach developing for Windows Azure with the mindset that it is an Operating System. Very much like in the days when we developed applications for deployment on different systems, we can use that mindset in designing and developing an application for Windows Azure. As a software developer, when instructed to develop an application that will be deployed on a particular operating system, there are things that we consider. Like how that particular OS works, how it reads and writes on the hardware, how its security features are implemented, how it manages the hardware resources etc. This is how one should approach designing and developing an application for Windows Azure, hence the mindset of looking and treating Windows Azure as an Operating System, on the Cloud, should do you fine.

 

And this brings us to our second point; on “how” you would want to approach software development for the cloud. This will cover a slightly modified SDLC, the design process etc.

 

Designing and developing for the cloud can be totally different, or exactly the same as what you and your team has been doing, depending on what SDLC or pattern you have chosen to adopt. However, I will not be enumerating programming patterns that you should adopt, that would be too many and enough for a separate blog in itself. Here, I will try to illustrate what I think will be a big change in your team’s methodology.

 

As you may have already researched, one of the great strengths of Windows Azure (particularly for startups or small ISVs) is that you can deploy your Web Application Straight from Visual Studio.

 

I don’t adhere to this tho. It is in my most humble opinion that a developer (specifically those who belong to a specialized team) should not have the ability to access the Windows Azure Subscription and deploy straight to it. *This is under the assumption that only the developers have access to Visual Studio.

 

A lot of problems may arise from this scenario, but I will express just one, my main concern. A developer may inadvertently deploy a version of the application that has not gone through QA or approval for promotion to testing OR production.

 

So, how to “solve” this problem that is not really a problem.. here is what I would propose to be the flow in a development environment with several stages and specialized people.

 

Development of course, happens within the development team. Testing will be through the Windows Azure Compute and Storage Emulators. If there should be need to actually test online, it will be a different scenario, that I shall illustrate in the next paragraphs.

 

After a successful build from the Dev Team, using Visual Studio they can “Package” the solution for deployment or promotion to a Staging Environment. Here we get to discuss another feature of Windows Azure (like being able to deploy from VS), that has not been really getting much of the spotlight.

 

All Windows Azure subscriptions have two environments; the Staging and the Production environment. The staging environment, as the name dictates, is where the application can be deployed to Windows Azure, run in the exact same configuration as the production, but will not be visible to the public. What this gives, is the ability to test the application in an environment that is as close to the production environment as imaginable. Now the question is; who shall be in charge of promoting, or uploading, the package and configuration file/s to the staging environment?

 

My suggestion would be to identify an entity in the development team that has previously had a similar role. Like a Deployment Manager perhaps. The one that was in charge, or took charge of caretaking for compiled code. This person shall be the one with access to the Windows Azure subscription, deploy using either Visual Studio or through the management portal, and notify the dev team or QA team of such a deployment.

 

In the event that the Dev team wishes to deploy to test for performance during development, the same process can be applied in deploying to staging.

 

Okay, this will be all for this entry. Next blog entry will take a look into specific areas of concern if you are a .Net Web Developer using ASP.net

 

Posted in Computers and Internet | 1 Comment