Sunday, June 26, 2011

Image Button Using Attached Property In Silverlight

In this post I will show you how to create Image Button using Attached property in silver light application. You can see the output of the example code in the Image 1 and what I want to achieve by using the attached property. Here you can see that i have image and text in a button control of the silver light.

Image 1

Code for the attached property is listed in List 1. Here you can see that I have static class with the name ImageButton. The in the class I have IconProperty. I have pass the property name "Icon" which is of type ImageSource and the owner is the ImageButton class. Then I have the GetIcon and SetIcon property of type ImageSource.


List 1

XAML code is listed in the List 2. Here you can see that I have added the reference of the attached properties which is located in the attached property folder. Next is I have set the Icon property (which is the attached property) of the buttons which are located in the Icon folder and also set the style of the buttons (in this case I have created new style so that I can place icon along the button text). Both buttons are located in the stack panel.


List 2

Next is the ImageButton style which I have created by replace the ContentPresenter of the original button style. In the Image 2 you can see that I have replace the ContentPresenter with the grid layout and  here you can see that I have place image control and also textblock control inside the grid control. I have two columns in the grid.

Image 2
The output of the example can be see in the Image 1. You can download the source code from here

All and any comments / bugs / suggestions are welcomed!

Saturday, June 18, 2011

Binding Command Inside DataGrid Using MVVM

In this post I will show you how to bind the commands inside the data grid control using MVVM pattern. For this post I have continue my last post which is used to explain the data pager using MVVM. For this post I have added DelegateCommand class which is added in the Classes folder. I have only one command in the viewModel (with the name HomeViewModel and is located in the ViewModel folder). The view for the Home is located in the View folder. Here you can see that I have added the HomeViewModel as resource in the home view which you can see in the Image 1.


Image 1
I have mentioned the step in the Image 1 which you can see in Image 1. I have set the name of the resource as homeViewModel in step three I have use same name to set the source of the binding both in the data grid and in the command of the HyperLinkButton. I have used hyper link button which is mostly used in the web. In the command parameter I have passed the CustomerID by using the CustomerID we can find the record from the list.

Image 2
In Image 2 you can see the output of the example code, here I you can see the delete command is added in the first column of the data grid and when you place mouse over the delete it will show the tool tip to show the contact name to delete. Hope you get idea of how to bind the command inside the data grid, by using same technique you can bind the add, edit commands which are commonly use in data grid.You can download the source code from here 

All and any comments / bugs / suggestions are welcomed!

Sunday, June 12, 2011

Retrieve rows in crm2011 subgrid with JScript

When I saw account entity I saw a grid which show related contact of the account entity then I think of reading the contact grid in JavaScript. After some search on google I found thread on stackoverflow Which has same question as in my mind and there as solution to that question as well posted.

List 1

I have modified the code posted on that question and modified code is listed in the List 1. Here you can see that element is search by id and I have provided name of the grid which is accountContactsGrid grid. The getRecordsFromInnerGrid function of the gridControl return the number of rows in the grid. The reason of getting the each row fourth column is shown below in the Image 1 as you can see that the fourth column has the detail of the cell in the row.

Image 1

In the inner loop I loop through each cell of the row and display outerText, the first two cell has empty string in the outerText as one is the checkBox cell and second one is the image cell. The name of the grid which I am using is taken from the dialog which is shown below in Image 2.


Image 2

All and any comments / bugs / suggestions are welcomed !

Saturday, June 11, 2011

Tab Properties Using JavaScript in MS CRM 2011

In this post I will show you some of the properties of the tab control. The JavaScript code is listed in List 1. Here you can see that I have set the name of the function loopThroughAllTab which you can call from anywhere. In the function I have used the Xrm.Page.ui.tabs.get() function which will return all the tabs on the page and I have store the list in the tabList. The getName will return the name of the tab control like general, details etc on the account entity. and the getLabel will return the label which is shown on the account entity like General, Details etc.Some times you need to compare the name or the display name to search for specific tab control.

List 1

The getDisplayState return expanded or collapsed value, depending on the setting of the tab control on the tab property dialog. It also has the counter set function which will be used to set the DisplayState of the tab control. And Last function is the getVisible which return either true or false depending on the visibility of the tab control.
Image 1
In Image 1 I have shown what function will return what on the tab properties dialog.

All and any comments / bugs / suggestions are welcomed !

Friday, June 10, 2011

Loop through OptionSet Using Javascript in Microsoft CRM 2011

In this short post I will show you how to loop through the optionSet option in Microsoft Crm 2011 in JavaScript. some time you need to check specific text or value in the optionSet and then enable/ disabled or show hide some of the control on the form.


List 1

In the code above listed in List 1 I have used the OptionSetControl.getOptions() function to get all the optionSet options and then use the lenght property which return the number of options in the optionSet. In for loop I have used the alert to show the option text and value.

All and any comments / bugs / suggestions are welcomed !

Thursday, June 9, 2011

CRM 2011 – Using Javascript to identifying Form context for the record

There are often situations when as a developer you need to check the form whether form is open for create new record or is open for update record. This can be very useful to check whether form is open for create which case need to assign some default values to the some of the controls on the form.JavaScript code is listed in List 1 here you can see that form can be open for six different context including the create and update context.

List 1
In the code above you can see that Xrm.Page.ui.getFormType() is used to get the context of the form. It will return the value of type number which will then check as I have do in switch statement to do appropriate action depending on the context in which form has opened.

All and any comments / bugs / suggestions are welcomed !

Wednesday, June 8, 2011

How to retrieve the Owner values in CRM 2011 Using JavaScript

In this short post I will show you how to get the values of the ownerid in Microsoft Dyanimics Crm 2011. You can see the code is listed in the List 1. Here you can see that I have get the id of the owner and name of the owner type and typename and also entityname.


List 1

You can see that I have get the 0 index value of the owner. Here  I have display the id, entitytype,  name , type and typename of the ownerid. id will be the GUID of the owner and name will be the full name of the owner.


All and any comments / bugs / suggestions are welcomed !

Sunday, June 5, 2011

How to retrieve the optionset text and value in CRM 2011

In this post I will show you how to get the selected text and value from the optionSet using javascript in Microsoft Dynamics Crm 2011

List 1


In the code listed in the List 1 you can see that I have used two option to get the selected value of the option set. By using getSelectedOption function which has the text and the value properties and second option is getText() and getValue() function which also return same values. The output of the getSelectedOption() function can be seen in the Image 1. I have display the values using watch here you can see that It has only two properties one is text and second one is value which is number type.
Image 1

The output of the getText() and getValue() can be see in the Image 2. Here you can see same values are displayed which are shown in the Image 1  Text is string type and value is Number type which you can see in the Image 2.

Image 2


All and any comments / bugs / suggestions are welcomed !

Saturday, June 4, 2011

Closing ChildWindow In MVVM by Using Attached Property

In this post I will show you how to close the ChildWindow of Silverlight using Attached property in MVVM. Let us start with the example code. For this example I have created Silverlight project of template "Silverlight Navigation with Accent Color" application. I have added new ChildWindow in the view folder with the name UserInputForm and then UserInputFormViewModel in the ViewModel folder which is the used to set as the DataContext of the UserInputForm.
I have created one attached property which is used to bind in the ChildWindow as the property of the ChildWindow DialogResult is not dependency property so it can't be bind. So I have created DialogResult property which is bind in ChildWindow which you can see in the Image 1.


List 1

In the code in List 1 you can see that I have set the value of the dialog result in the OnSetDialogResultCallback. In the OnSetDialogResultCallback the dependencyObject is converted to ChildWindow and then check for the ChildWindow for null and if not null then set the value of the ChildWindow DialogResult.

Image 1

In the UserInputFormViewModel I have two commands save and the cancel which are bind to the save and cancel buttons on the UserInputForm. When ever user click either the save or cancel button I have set the value of the ModelDialogResult property true in case of save button and false in case of cancel button. In the Closed event handler of the UserInputForm which I have registered on the Home cs file I have check the DialogResult property. Hope You get idea of how to close the ChildWindow using MVVM.You can download source from here.

All and any comments / bugs / suggestions are welcomed !

Thursday, June 2, 2011

Plug in and Work Flow Template for Visual Studio 2010

While learning Microsoft Dynamics CRM 2011 I have search a lot for learning and during that search I have found some useful stuff which I want to share with you guys. When we work in Visual Studio there is almost every template there according to the developer needs from web application to desktop application and Silverlight  application to class library for both the Silverlight and desktop etc. But while working with Microsoft Dynamics CRM 2011, If developer work in the Visual Studio to develop plug in or work flow then there is no template in the visual studio. But during my search I have found two template for the visual studio for the Plug  in and work flow activity. You can download templates from the link as given below.
  1. Plug in
  2. Workflow Activity

After downloading from above link what you have to do is to place the above .zip file in the directory        \My Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\CRM 2011. In directory  name I have created folder with name CRM 2011 which is appeared in the Installation folder which you can see in the Image 1.
Image 1
Note : When you create plug in project using the above mentioned template you have to add the reference of the microsoft.xrm.sdk dll which is placed in the bin folder of the CRM SDK as I have plae my CRM SDK in D drive so my path for the bin folder will be D:\Crm\CRM SKD 2011\bin.

All and any comments / bugs / suggestions are welcomed !