Posts

Showing posts from August 22, 2010

WebBrowser Control in WPF

Image
In this article, I am going to show how we can use WebBrowser control to show html document within our WPF application. WPF introduces WebBrowser control to ensure that we can show html pages embedded inside the control. Here I use 2 buttons also to go back and forward. This is my XAML code < Window x : Class ="WebBrowserControlIn_WPF.Window1"      xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      xmlns : x ="http://schemas.microsoft.com/winfx/2006/xaml"      Title ="WebBrowser Control in WPF" Height ="Auto" Width ="Auto" Loaded ="Window_Loaded">     < Grid x : Name ="LayoutRoot" Width ="Auto">         < Grid.RowDefinitions >             < RowDefinition Height ="10"/>             < RowDefinition Height ="*"/>         Grid.RowDefinitions >         < Grid.ColumnDefinitions >           

Creating Fancy Tooltips in WPF

Image
Each control in WPF has a Tooltip property that can be accessed through XAML or code behind. The Tooltip property can host any kind of controls such as a rectangle, text block, or a panel. In other words, we can display another window with any number of controls as a tooltip of a control. The following code creates a simple tooltip for a button control.        < Button Width ="100" Height ="30"> Click Me             < Button.ToolTip >                 < ToolTip > This is a tooltip test for a button control. You                      can click me if you want but I will do nothing for you.                 ToolTip >             Button.ToolTip >         Button >   The output looks like Figure 1. Figure 1. A simple Tooltip As I said earlier, a Tooltip can host any number of controls. For example, in the below code, a button tooltip hosts a StackPanel with two children StackPanels. First StackPanel hosts an image and a text block and

Making Timeline Control for DataGrid in WPF

Image
Now that we have the brushes we can draw the rectangles. The horizontal rectangle is for Hour and the vertical rectangle(s) for minute(s). As you see from the above xaml display, we have Minute rectangles Visibility made as Hidden. Here is the trick for visibility; if we use visibility as collapsed the space taken by the rectangle is gone and the next rectangle would take it's place. In order to do that we need a Dependency Property which would contain the minute(s) as user has to give. As you see in the above code display, the MinutesProperty is created as a Dependency Property. It is a type of TimelineControl and it would have the value as string. Let's have the Loaded event of the User Control, where we will make the minute rectangles visible based on the minute list provided. See full details:  http://www.c-sharpcorner.com/UploadFile/dpatra/2025/

Difference between DataContext and ItemsSource in WPF/Silverlight

In this post I will try to illustrate the difference between DataContext and ItemsSource property in Silverlight/WPF. These two properties don't serve the same purpose. DataContext expects an object type where ItemsSource expects IEnumerable type objects. DataContext is a dependency property is exposed by FrameworkElement base class,where as ItemsSource is defined by the ItemsControl class. All the descendants of FrameworkElement can utilize the DataContext property and set an object to its value. But we can only set a type of IEnumerable(or instance of class that derives from).   DataContext does not generate template, it only used to hold common data for other controls to bind. In terms of ItemsSource property, it is mainly used to generate template regardless of you set it in XAML or in the code behind.   DataContext is mainly used to hold common data that other child want to share. Thus it can be inherited by other child elements without problem. But for Ite

Change Theme Dynamically in Silverlight 4

Image
Introduction In this article we will see how we can change theme dynamically in Silverlight 4. Create Silverlight Application Fire up Visual Studio 2010, and select Silverlight Project from the templates. Name the solution as ChangeThemeSample. We need to have System.Windows.Controls.Theming DLL reference, along with the references of the Theme DLLs. The following figure shows the assemblies to refer for themes. As you see we have chosen all themes, but it's not necessary. You can take the required themes as per your requirement. Now let's create an User Control which will have the log in form. We are not going to see any code behind for this User Control as it's only a demo. So the design would look like the following. Now, come back to MainPage.xaml, where we would place the user control along with the Combo Box to populate the Themes. The following is the xaml code for the above design. Now, let's populate the themes

Introduction to Visual Studio 2010 DataTips Pinning

Image
In this article, we will look into new feature of VS 2010 called as DataTips pinning. This feature is available in all editions of VS 2010. DataTips is a nice feature helpful while debugging an application. It works only in break mode to view contents of a variable within current execution scope. A DataTip appears in source code window, when you place a mouse over a variable in current scope and it disappears on mouse out. In VS 2010, we can pin a DataTip so that it remains open and sticks to a specific location in source code. We can drag a DataTip to any location within source code window. To pin a DataTip, right click on a variable and click Pin to Source as shown below:    A pinned DataTip closes, when debugging session ends or clicking on close icon. We can expand members of variable like array or object by clicking + sign before variable name in DataTip See full details:  http://www.c-sharpcorner.com/UploadFile/satisharveti/2339/Default.aspx

Using an ASP.Net Master Page with theme and CSS

Image
Using an ASP.Net master page with a theme and CSS can be tricky.  Themes and master pages came out in 2005.  There were hundreds of articles written about them at the time.  Since then, however, the way we do web development has changed a great deal.  It's time to readdress the subject.  In this article, we'll cover the basics.  Then we'll add stylesheets for printing and for Internet Explorer only. The Problem Suppose I want to make a website without .Net, one that's nothing but HTML and CSS.   My HTML head might look something like this: Notice I'm linking in three CSS stylesheets, style.css, print.css and ie.css.  Style.css, is the main CSS file for my website.   The "media" attribute indicates that this CSS applies when my page is displayed on a computer screen or projector. The media attribute for my second CSS file, print.css, indicates that this file contains special CSS which only applies when someone is printing my page.  I can add

Customize AutoCompleteBox in WPF

Image
Introduction In this article we will see how we can customize an AutoCompleteBox in WPF.   Creating a WPF Project Fire up Visual Studio 2010, create a WPF Application, and name it as AutoCompleteSample2. Sometimes we need to display more than one item in the auto complete box suggestion. For example state code with state names. So we got two columns in the suggestion.  I was trying hard to customize it in Expression Blend, but turns out it was very simple. Let's have a class of Codes with the following properties.   Now let's create a list of Codes and bind that to the AutoCompleteBox.   Now without customization, let's run the application and see what we are getting as output.   So we are getting the Class name instead. Now we can simply customize the Item Template of the AutoCompleteBox as follows:   As you see in the above code display, I have two textboxes which would bind to the respective properties of the ItemsSource. Now let's run the a

Hosting WCF in SharePoint 2010

Image
Introduction SharePoint 2007 provided the capability to add custom ASMX web services. Web Services could be deployed to the LAYOUTS folder, or could be deployed to the ISAPI folder and supported accessing site settings and list data under the SharePoint user context. Since SharePoint 2007 was built on the ASP.NET 2.0 model, it did not natively support web service enhancements that were introduced with Windows Communication Foundation (WCF) in .NET Framework 3.0 and 3.5 or the additional WCF-based service frameworks like ADO.NET Data Services (now WCF Data Services). For those familiar with writing custom ASMX services for 2007, there were some pitfalls. Since SharePoint requires dynamic service endpoints (the ability to call the web service using any site-relative virtual path under the /_vti_bin/ folder), you had to hand-tool your WSDL files to dynamic service locations. This had to be done every time your changed your web-service signature. Not terribly complicated, but

How to Display data from External Databases in Share point

Image
Easy way to Display data from External Databases in Share point without using Business Data Catalog. Here I am showing you how to display a data from external database in Share point using SharePoint designer 1. As usual you have to open the site in share point designer and open the page where you want to display the data. Please make sure you have checked out the files first. 2. Click Insert ASP.NET Controls and select More ASP.Net Controls. 3. As shown below select Grid view form Data Group and Drag that to your share point page. 4. You will get a screen like below. 5. From Choose Data Source Select New Data Source. 6. Give name for the data source. See full details:  http://www.c-sharpcorner.com/UploadFile/Roji.Joy/2811/

Developing Autosuggest using JQuery and Webservices

Autocomplete is an input field that enable users to quickly finds and selecting some value. By giving an autocompleted field on entering some value  into it. The code starts searching for matching entry and displays a list of matching values. By entering more characters, the user can filter down the list to better matches. Namespace to be import using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; autosuggest.asmx (a web service file) [ ScriptService ]     [ WebService (Namespace = "http://tempuri.org/" )]     [ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]     [System.ComponentModel. ToolboxItem ( false )]      public class AutoComplete : System.Web.Services. WebService     {          public class Employee         {              public int ID { get ; set ; }              public string Email { get ; set ; }              public Employee()             {                  //