Showing posts with label Visual Studio 2012. Show all posts
Showing posts with label Visual Studio 2012. Show all posts

Friday, January 3, 2014

How to add dependency property for custom control in wpf

Introduction

Ever had problem that your custom controls dependency property is not getting updated when you changed it from the control? Probably most of the wpf developer already know it still sharing it because, I kind of lost few minutes in darkness when I found that my custom control is not updating the target dependency property.

Enough talk show me the code

Well here is the code!. Do you find anything wrong with it? Seems absolutely fine.

public static readonly DependencyProperty SelectedValueProperty =
DependencyProperty.Register(
"SelectedValue", typeof(DateTime?), typeof(DateTimePicker), new UIPropertyMetadata(null, OnPropertyChanged));

public DateTime? SelectedValue
{
get
{
return (DateTime?)this.GetValue(SelectedValueProperty);
}
set
{
this.SetValue(SelectedValueProperty, value);
}
}

Now, my view model has a notify property which looks like the below code


public DateTime CurrentDate
{
get
{
return this.currentDate;
}
set
{
this.currentDate = value;
this.OnPropertyChanged("CurrentDate");
}
}

And the data is hooked via xaml binding, code below.


<riteq:DateTimePicker IsEnabled="True"
VerticalAlignment
="Top"
SelectedValue
="{Binding CurrentDate}"
x:Name
="TimePicker"
DisplayMode
="DateOnly"
CalendarSelectionMode
="SingleDate">
</riteq:DateTimePicker>

Look a perfect setup for the code. And at first glance we didn’t had any problem, until we tested it. No matter what date I select from my custom date picker, it never updating the CurrentData property of the view model.


So there is something wrong with the controls property. I tested and debug the code seems to be the binding expression working fine.


Then I found a piece of code where I set the dependency property’s value. As soon as i set some thing there the property’s binding got broken.


Here is the code.


if (this.cal.IsDateChanged)
{
this.SelectedValue = this.cal.SelectedDate;
}

Its a simple property setting , but this was causing problem, then when crazy with googling and found an every easy fix for my problem.


And the problem is with my definition of the dependency property. I was using “UIPropertyMetadata”. I changed the definition of property change call back to  “FrameworkPropertyMetadata”, and every thing back to normal and working again. here is the revised defination for the dependency property.


public static readonly DependencyProperty SelectedValueProperty =
DependencyProperty.Register(
"SelectedValue",
typeof(DateTime?),
typeof(DateTimePicker),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPropertyChanged));

So now we are using FrameworkPropertyMetadata as property meta data. And that is the fix for my problem.


Lesson

If you need any dependency that can be changed inside the control please use FrameworkPropertyMetadata for dependency property definition.

Thursday, September 12, 2013

Visual studio 2012 Blue Theme

Dear Community, I believe lot of the die hard fan of Microsoft development platform  wondered why visual studio 2012 got rid of the blue theme, in my personal opinion i really liked it, then while working and viewing videos in channel 9  I discovered that we can have different different colors theme in visual studio, and that’s  been there from the beginning.

Man I am stupid, should have figured it out that they have some kind of plan for that. Any way the easies way to get this blue theme going again in visual studio is to use extension.

How to get the blue theme?

Go to visual studio 2012’s extension manager and then search for “Color” in online category.

image

You will find couple of interesting extortions, Download the “Visual Studio 2012 Color Theme Editor”

image

The download and install will begin instantaneously, after that the Visual studio will be required to restart.

After restart you will get option like the below where you can choose your color theme. Choose the right one. In my case I have chosen “Blue”.

image

You can also customized the theme and create your own theme, but that is a whole other story. Until next time. Happy coding.

Friday, August 2, 2013

Team foundation server windows explorer extension

We all used svn that’s for sure for personal use or perhaps company policy to use it doesn't matter, in source control race TFS is getting behind. At lease i felt it, but some recent improvements now taking this back bench product to front bench.

For instance we can have git like behavior in tfs if we want, cool right?. But today I wish to share a different type of tool that can ease the tfs experience a little bit better, in fact its a windows explorer extension, named “Microsoft Visual Studio Team Foundation Server 2012 Power Tools”

You guys can download it from “http://visualstudiogallery.msdn.microsoft.com/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f”

I have used it and its kind of can give you a feeling like tortoise. It has overlay icons just like svn.

image

Now some critic, the extension has relatively slow in performance, at least in my system. It doesn't have branching or switching stuff like other source control extensions, its primitive but at least now we have an extension.

I got excided to realize that now i can add documents folders and other stuff in tfs without need to open visual studio. so its cool and if we all start using it hopefully more feature will be available in future. 

Thursday, July 4, 2013

Thousands of warning! in visual studio 2012? Why?

So what happen is, I had my XML documentation file checkbox in build tab of project was checked. And I had few service references in my project.

As you can guess all of the service ref has around more than 2000 methods, since this checkbox was checked all the public methods of service proxy class was giving a warning about summery of the function.

image

It was frustrating to see that amount of warning in my project, Then unchecked the checkbox and wallah all the warning are gone.

Inner peace is on,,,,

Thursday, January 3, 2013

WCF Service Optimization: An interesting technique to split your *.svc.cs file to have more manageable WCF service

Introduction

WCF (Windows communication foundation) is the service layer foundation and the base of SOA in Microsoft dot net, what will happen when you have a huge WCF service consisting of 5000 operation contract. This is not unreal at all, if you design a service bus for a large intranet application, where 1000 employee using your application and doing day to day operation and your WCF service hits per second is about 2000. You can do so many thing to optimize it, first of all you can cluster the service and then apply load balance. So horizontal scaling is a solution.

Now if you are given a task to optimize the operation and each time you need to look at the service you have to find it in a large class where you have about 5000 operation contract. How developers will maintain this huge code base?

Fortunately we have few solutions to that problem

Today we are going to see 1st of many solution

split your *.svc.cs file

This does not help in optimization of the service rather managing the file and the codebase. First of all I would split the svc file in to several pieces. Each will contain in about 100 methods, still we would have 20 files for the svc file, its kind of sounds different but, would help managing 2000 methods, each file will contain domain specific methods for the service.

How we do it?

We will add class with almost same name as the service, for instance if we have a WCF service named “myservice.svc” then the code behind file is  “myservice.svc.cs”. Off Course its not necessary to have svc.cs file with the wcf service we can have only the declaration.

Below a code example is given,This is how a real world service which is out of refactoring and maintain for a while looks like.

image

Figure: Log Class of 2000 method

In above screenshot If you carefully look at the scrollbar of the method dropdown of the visual studio, you will have an idea how much its doing.

So now we need to optimize this in perspective of code management. As we already discussed the technique. we will split this in to several pieces, luckily we have a partial class concept in c#, so we would split this in to several pieces according to class responsibility domain.

Naming convention for the partial class. “myservice.[responsibilityDomain].svc.cs” that’s the filename of the class. In practical case I have named on of my partial class as “ReliantDataConnect.CandidateOffer.svc.cs” I have moved all the methods related to CandidateOffer in this file.

Now Lets say we have added another partial class file name “ReliantDataConnect.Resource.svc.cs” using the following wizard window.

image

Figure: Add a new class

And after moving the related methods in the partial class the partial class may look like below screen shot.

image

Now problem is the partial class will be visible in solution explorer as a isolated file rather part of the WCF Service. Below how it looks like after adding the file.

image

Now if we can add this file as a dependent file of the ReliantDataConnect.svc file this will save us form watching isolated file, and make a combined file. Here is how we do it.

Make a file dependent on another file in visual studio

First of all we have to open the project file in note pad or text pad or note pad ++ which ever you like. Then find the file name that we added “ReliantDataConnect.Resource.svc.cs”, finally add DependentUpon Child node and specify the file name in our case its “RelaintDataConnect.svc” Now saved the file. Close it. If visual studio is open it should already warn you that file is been modified outside and reload is necessary. Reload to proceed.

image

After reload you will see that the file is now part of svc file.

image

Cool right?. Well for now you can go and browse other blog, I will get busy with creating 20 more class file for this project. Until next time.

Masudur Rahman is out.

Thursday, September 13, 2012

Visual Studio 2012 Web publisher Wizard messed up!

Hi guys want to share a tittle experience while testing some new feature of visual studio 2012, its one of the oldest feature, but found a bug today. Bellow I shared the screen shot.

image

Ah… looks kind of smashed right?, How did it get there, few simple steps actually,

Step1: Right Click on Web project and select “Publish” to lunch the publish wizard.

Step 2: Click on Click on the drop down and will find a new option called “<New…>”

Step 3: Now click on the <New…> this will bring out a window like bellow

image

Step 4: Now don’t put anything on the text box of the “New Profile” dialog , rather click on “Cancel”

Step 5: Now you would see the connection , settings, and preview tab got enabled.

Step 6: Click on Preview tab, you would see that the window is kind of messed up.

Hope it would be fix soon.

Until next time , cheers!

Friday, August 31, 2012

Visual Studio 2012 got rid of all unnecessary things!

I must say that I am not that much excited with the release of Visual Studio 2012, as I must learn everything from scratch again, in fact need to figure out what has changed since 2010. Once again I must confess that I liked vs 2010 more than vs 2012, let see where it goes as I would be exploring visual studio in coming weeks.

image

Only required project are in the window now Open-mouthed smile. No more lots of project template, but still we have one very interesting option now we can directly use online templates.

image

Man! why is this black and white crappy look, may be because of performance, once again I like vs 2010 more. I will create a web application now and see what is the difference.

Did anyone noticed we have still the web site creation feature in vs2012.

image 

Believe it or not web site template is not more improved and equipped with lot of modern technologies, I kind of sounds stupid but my feeling is funny and I can not express properly. Hope this will rock the world of Microsoft based technology developers.

Cheers!.