Infosys Microsoft Alliance and Solutions blog

Main

April 28, 2008

WPF ObjectDataProvider vs Direct Object Use

When using object instances in XAML, there are two ways to use them. One is to directly create them as resources, assign and key and use where ever required and other is to embed them inside of ObjectDataProvider and then use.

I have worked with both ways and was curious to know the differences between the two and benefit of using one approach over another. I can across this old blog by Beatriz that explain this very well. Along same lines, here is some discussion on XmlDataProvider as well.

April 17, 2008

WPF makes Designers and Developers friends again

I have been playing around with WPF for a while and have been blogging about some of the technical aspects on it. However today I will like to touch upon another important aspect of WPF and that is designer-developer connect.

Having worked on Windows Programming using C++, MFC etc for a decade and working with the various controls, it is a real pleasure to see the capabilities now available to WPF developers. It is true to a large extent that with WPF and XAML and the tools like Expression Blend, designers and developers can work lot more closely than ever before. The working closely is more towards the ability for designers to style the UI for the WPF application and the developers to write the code for it.

Continue reading "WPF makes Designers and Developers friends again" »

April 11, 2008

WPF Data Binding

WPF data binding a very effective way to bind .net CLR objects to WPF UI controls and ensure appropriate updates (by proper use of binding mode and property change notifications). However it can become a bit tricky if not used properly. I recently found these interesting 10 points about WPF data binding. I am sure you would find them helpful as well.

April 10, 2008

WPF - Passing string to ConverterParameter

There are enough online sources that talk about how to buid and use custom Converters in WPF and also how to pass parameters to these converters. However for some reason, all these examples tend to either use a single integer or a single word string. So recently when I had a need for passing a sentence as parameter, I was confused.

Fortunately the simple trick of using single quotes inside of double quotes to provide strings worked in this case as well. Following are two ways you can pass a string that has multiple words to a converter.

Continue reading "WPF - Passing string to ConverterParameter" »

April 04, 2008

WPF - Binding to Image Control

Overtime, I have used different approaches to binding pictures to Image control in a WPF application. I have seen various questions on the WPF forum as well on this topic. The information is all available out there, but scattered. Hence, I decided to create a sample application to demostrate the various scenarios that can exist when you need to use the Image control to display pictures.

Continue reading "WPF - Binding to Image Control" »

April 03, 2008

ASP.NET AJAX Perils

ASP.NET AJAX is come a long way since its inception a few years back and my personal take it is that it in a hype cycle right now, where everyone is trying to jump on-board and create AJAX based applications. Needless to say that it has its own benefits, but there definite downsides to it as well. You can read a set of 10 important aspects around AJAX here.

It is known that though it gives a flicker free UX, the under-the-hood story tells a different tale. Having read about it, some days back, we did a small experiment to really see the kind of differences one can get with different approaches and you can read about our findings in this report (Download file). The scenario we took is very simplistic, but the results are still eye-opening.

March 26, 2008

WPF - Updating XmlDataProvider when source XML changes

Some days back i had answered a question on the WPF Forum on how to ensure that when the base XML file changes, the XmlDataProvider is udpated and hence the bound control on the UI.

The key is to set a watch on the particular XML file for changes and then update the provider appropriately. See details here. This solution works fine, but I didn't particularly like my initial code that I wrote since the FileSystemWatcher was set externally. It would be better if this could be self contained within the XmlDataProvider itself.  

Continue reading "WPF - Updating XmlDataProvider when source XML changes" »

March 18, 2008

Expression Blend issue with WPF Data binding debugging

Some days back I had pointed to the blog by Beatriz on how to debug WPF data binding errors. I have been using the PresentationTraceSources.TraceLevel feature (available with .NET 3.5) since then and have found it very easy to use and very effective in resolving my data binding errors.

However recently when I opened a XAML, which had this debugging feature enabled, in Expression Blend 2.5 March Preview, I got an error. The XAML won't open in designer and showed "Invalid XAML" with details as 'The member "TraceLevel" is not recognized or is not accessible'.

Continue reading "Expression Blend issue with WPF Data binding debugging" »

March 12, 2008

WPF TextBox Memory Issue

Some days back, I had blogged about this issue and suggested how to set global style to counter this. However it turns out that with that you may run into 'Cannot use UndoService while it is disabled' related error. To address that, you will need to modify the style using a DataTrigger as below.

        <Style TargetType="{x:Type TextBox}">

            <Style.Triggers>

                <DataTrigger Binding="{Binding Path=IsLoaded, RelativeSource={RelativeSource Self}}" Value="True">

                    <Setter Property="UndoLimit" Value="0" />

                </DataTrigger>

            </Style.Triggers>

        </Style>

MS has accepted the behavior behind this as a bug. Read more discussion on this here.

March 10, 2008

WPF XmlDataProvider, Working with External XML Files

Recently on the WPF Forum I came across an interesting problem about use of XmlDataProvider in XAML and its ability to load external XML files. It took a bit of a struggle, but eventually I did manage to get it working. Here I will try and explain it in some detail so that others can also benefit.

We all know that one can easily bind to inline XML in XAML or can load that from external file. If working with inline XML, you usually use XData to specify the XML file content.

Continue reading "WPF XmlDataProvider, Working with External XML Files" »

March 06, 2008

Expression Blend 2.5 still has some issues with Globalization

Last week I had blogged about an issue with Expression Blend Dec 2007 Preview when working with Globalization and Localization. Yesterday at MIX 2008 Microsoft has launched Expression Blend 2.5 March 2008 Preview along with SilverLight 2.0 Beta. For a list of all the products announced during MIX check here.

With the new version of Expression Blend available, I went ahead and upgraded my machine with it and decided to give it a shot for the Globalization issue I had faced earlier.

Continue reading "Expression Blend 2.5 still has some issues with Globalization" »

March 01, 2008

WPF - TextBox memory leak issue

Earlier today on the WPF Forum I hit upon this issue about memory leak in TextBox. MS has responded saying it is by design. I am not entirely convinced as to how consuming unlimited memory could be a good design decision. I have been using WPF for a while now and wasn't even aware of this property on TextBox. I am sure many others won't be.

Anyway, the solution discussed there is to set the UndoLimit property of TextBox to 0. Instead of setting this for all TextBoxes in your code, it can more easily set in App.xaml as an application resource so that it is applicable to all TextBoxes by default. You can explicitly undo for specific ones via code or local property setting.

    <Application.Resources>  
        <Style TargetType="{x:Type TextBox}"> 
            <Setter Property="UndoLimit" Value="0" /> 
        </Style> 
    </Application.Resources>

February 29, 2008

Expression Blend issue with Globalized WPF Application

Recently while supporting a project on converting their WPF application for globalization and localization support, we faced an issue in being able to work with Expression Blend 2 Dec preview. We used the recommended approach for globalization and localization and after doing all that Expression Blend failed to load the user controls in design view.

You would get an error like this - "MissingSatelliteAssemblyException: The satellite asembly named yourassemblyname for fallback culture 'en-US' either could not be found or could no be loaded. This is generally a setup problem. Please consider reisntalling or repariring the application."

Continue reading "Expression Blend issue with Globalized WPF Application" »

February 26, 2008

Querying Store Procedures(SP) returning Multiple Result Sets in LINQ to SQL (L2S)

L2S (working with designer in VS2008) works fine as long as SPs return data from a single table; problem arises when the SP returns multiple result sets and things become complicated when the data in the result sets is from a combination of tables.

Continue reading "Querying Store Procedures(SP) returning Multiple Result Sets in LINQ to SQL (L2S)" »

February 25, 2008

Group By Many/Multiple Criteria using LINQ to SQL (L2S)

Developers may find it annoying for not finding an out of the box query operator in L2S to group by many/multiple criteria, which is used very frequently in T-SQL queries.  No sweat, there is an easy way out, will try illustrate the same here.

Continue reading "Group By Many/Multiple Criteria using LINQ to SQL (L2S)" »

February 14, 2008

Debugging WPF Databinding errors

For an application I was working on recently, I had a tough time with debugging some of the data binding issues. Then I came across this excellent blog. My personal favorite is the new Trace Level feature of .NET 3.5. For some reason, I could not get the second option to work.

February 05, 2008

Required Field Validation in WPF

In my earlier blog on user input validation in WPF, I had discussed about how extension methods can be used to provide for custom valiation logic. If your need is more simply only mandatory fields, a validation that the RequiredFieldValidation control provides in ASP.NET, you could very well use the concept of Data triggers in WPF.

One of the key benefits triggers offer is that they can be effectively managed within the XAML without usually requiring much of procedural code. Also since triggers are raised on specific actions/events, they are automatically undone when the action/event is over. This comes handy and saves code, since otherwise in procedural code, you need to handle both cases (something that is seen in my work with extension methods).

Continue reading "Required Field Validation in WPF" »

February 04, 2008

Are Remote MSMQ Queues Reliable?

I have played around a bit with MSMQ private queues and documented some of my findings earlier. In my first blog on this topic, I had captured how the naming of the queue is critical to connect to the right queue.

If it was local private queue, you could use - ".\\private$\\queuename"

and if it was remote private queue, you use - "FormatName:Direct=OS:machinename\\private$\\queuename"

Continue reading "Are Remote MSMQ Queues Reliable?" »

January 31, 2008

Working with MSMQ Journal Queues

In one of our internal forums, recently, someone had posted a query regarding issues in connecting and receiving messages from journal queues. The exception they were getting was "Queue ID is not registered in DS". I hadn't worked with Journal queues before, but this error seemed to me to be related to the queue path.

In my earlier blogs (here and here), I had discussed about the importance of specifying the right name for the queue and also mentioned how the path will typically look like. I decided to give it a try and created a private queue on my local machine and enabled journaling on it. Enabling journaling is as trivial as checking a checkbox in the queue property window.  You can also enable it by setting the UseJournalQueue property on the message.

Continue reading "Working with MSMQ Journal Queues" »

January 30, 2008

Hierarchical Data Categorization using LINQ to Objects in n-tier applications

The intention here is not to talk about LINQ; rather to apply LINQ in enterprise applications. A typical n-tier application consists of Presentation, Business/Service and Data layer and the communication across the layers is done through Presentation, Services/Business, Data entities. We write translator classes which maps the Data entities to their corresponding Service entities and so on. This is fine as long as the mapping is one to one. The problem arises when we have store procedures (SP) returning composite entities. The situation gets complicated when we have to parse the composite entity returned from SPs into a hierarchical parent-child structure. With LINQ to Objects this task is very much simplified.

Continue reading "Hierarchical Data Categorization using LINQ to Objects in n-tier applications" »

January 28, 2008

Custom User Input Validation in WPF

Building any application that works with User Input cannot be complete usually without having some sort of validations for the input values. WPF is no exception. There is an interesting discussion around WPF validation on Paul Stovell's blog

Martin Bennedik has written a WPF Validation Block over Microsoft's Enterprise Library 3.0. WPF 3.5 also brings in additional validation support via the IDataEffortInfo Interface.

Continue reading "Custom User Input Validation in WPF" »

January 24, 2008

Importance of Application.DoEvents

Recently a colleague of mine shared a code that he was working on where he was playing around with Asynch ADO.NET. He had a simple WinForm application. On the click of a button, he was making calls to the DB to get data. To try out the asynch features, he had introduced delays in the code.

Continue reading "Importance of Application.DoEvents" »

January 23, 2008

Unit Test Trust Issue on Vista

Further to my unit testing experiments that I have been blogging about in the last few days, I was playing around with the DashCommerce starter kit. After installing and configuring the site, I started by creating some tests for the code in the App_code folder.

The test creation was successful and I was all set to run. But luck was against me and I got compilation errors regarding missing namespace. As I had mentioned in my earlier blog, the testing happens via private accessor and since its creation happened successfully, ideally I shouldn't  have had a need for adding explicit references and namespaces to my test project.

Continue reading "Unit Test Trust Issue on Vista" »

January 22, 2008

Debugging ASP.NET Unit Tests with VS 2008

In my previous blogs (here and here), I have been discussing about unit testing on an ASP.NET web site that is hosted on IIS. While doing the work on that, I also had a need to debug my test case. The documentation on MSDN talks about putting break points and attaching to w3wp process and then debug the tests.

This however didn't work for me on VS 2008. What worked was adding the System.Diagnostics.Debugger.Break() call in my code and then running the tests like normal. When the code hit the Debugger.Break line, it asked me, which debugger to use and I selected the already open VS 2008 instance and it took me to the correct line of code and i was able to debug.

January 21, 2008

ASP.NET Unit Testing on IIS

In my previous blog I had mentioned about the issue in generating private accessors for ASP.NET code that is hosted on IIS. Does this mean that we can't test the web site if hosted on IIS?

You can, but it will be a bit more complex and you may not be able to cover all scenarios. The idea is to work with the PrivateObject that is available from the test context. In the previous blog, I had talked about a web site with a Calculator class in the App_Code folder that i wanted to test. Let's continue with the same example.

Continue reading "ASP.NET Unit Testing on IIS" »

January 18, 2008

ASP.NET Unit Testing issue on IIS with VS 2008

I was recently trying to dirty my hands on using the Unit test framework that comes with Visual Studio. I decided to give it a try on my newly installed VS 2008. I created a pretty trivial ASP.NET site hosted on IIS with a Calculator class that I put in App_Code folder and generated the tests.

One of the key differences in working with Unit test framework for ASP.NET as compared to other projects like Winform or Class library is that the code in ASP.NET gets compiled dynamicall into various assemblies and hence we can't bind to a specific assembly upfront. Check more details on this here.

Continue reading "ASP.NET Unit Testing issue on IIS with VS 2008" »

January 02, 2008

Querying user details from Active Directory

During a recent project, we had need for querying and working with Active Directory. Searching on net, gave lots of help, but most were around creating and managing users. Our need was simple - to get some user specific details from AD.

The trickest part of working with AD is the AD structure and what properties have been defined and hence available for querying. Without really knowing this, one can continue to grop in dark for long hours without much success.

Continue reading "Querying user details from Active Directory" »

November 30, 2007

Silverlight 2.0

I have been playing around with Silverlight for a while now and like all, have been eagerly waiting to get some out-of-box controls that will ease the development effort.

It is good to hear that Silverlight 2.0 will contain a good initial set of controls. The beta of this new version is expected around Q1 2008 and there is lot of speculation that RTM will be around June/July 2008.

November 20, 2007

Visual Studio 2008 Available

The must awaited Visual Studio 2008 is now available. Those who have MSDN subscriber download access, can download it from here. You can directly download the trial version from the home page itself. More details around this can be found here. In case you are facing issues in uninstalling the old Beta version and installing the new version, check here.

I am however facing issues with the new download manager. I keep getting network connection error. I will keep checking this up as I want to quickly download and start using this version of Visual Studio.

[Edited:22 Nov 2007] Full version of VS 2008 Professional Edition is available on MSDN subscriber downloads now.

November 12, 2007

Visual Studio 2008 RTM

Visual Studio 2008 is expected to RTM later this month. It should be available on MSDN Subscriber download, but the general off-the-shelf availability is still early next year.

November 01, 2007

It is Today - 1st Nov 2007

You would be aware of the expiring of VS 2008 Beta 2 VPCs today. If you have watching the VS Developer Center, you would have noticed the new updates on this. Jeff has mentioned in his blog about what happens with the existing VPC and mentions the 3 alternatives going forward

  • Upgrade the base OS with valid license
  • download the newly published VPC images from here
  • continue to work with the existing VPC and keep rebooting every 1-2 hrs.

Since downloading the 8 files, required for the VPC (not including the base image), took quite a bit of time for me, I will continue to use the existing VPC as is, as I can live with the reboot requirements for now.

October 29, 2007

VS 2008 Beta 2 VPC Expiring on 1st Nov 2007

If you have been playing around with VS 2008 Beta 2 VPC, note that the VPC unlike earlier thought, will expire on 1st Nov 2007 itself. In case you have been using TFS along with the VPC, follow the steps mentioned at Moving Team Foundation Server to take a backup of your DB and prepare to move to the new VPC.

Since the timeout is at OS level, it is still being researched if anyone will be able to access their data on the VPC after 1st Nov 2007 or not. Additional guidance will be made available shortly. Keep a watch here for latest information. 

 

September 03, 2007

Logging Events with User details

The other day a colleague asked about how to provide information for the "User" column in the Event log. The EventLog.WriteEntry method has various overloads, but none that allows you to pass the user details.

There is an EventLogEntry class also that .NET provides, which has a UserName member, but it is read only property and is used to query event entries from the log. This means that by using .NET APIs there isn't a way to provide the user name for event log entries.

Continue reading "Logging Events with User details" »

August 21, 2007

Silverlight on VS 2008 Beta 2 VPC

The other day I decided to try my hands on building a Silverlight application using the Alpha 1.1 refresh on my newly downloaded VS 2008 Beta 2 VPC. I built an extremely trivial application with a text box to display some text. However on running, I didn't see anything and didn't get any error as well. I played around with the text foreground color, visibility and opacity properties but no luck. I could see things fine in the Expression Blend.

So what was wrong and why was IE not displaying it. I then found that this is due to the Enhanced security configuration for IE. I didn't get any warning. Probably when the VPC was built the Continue to prompt when Web site content is blocked option was unchecked !! Anyway, removing the enhanced security configuration did the trick and the application started to work properly.

August 02, 2007

WPF and AppDomains

In my earlier blog I had talked about how to work with AppDomains and the issues I had faced. I had a chance to interact with Hua Wang from Microsoft and it was very enlightening.

There are specific things that need to be taken care when creating and destroying AppDomains in WPF. .NET framework 3.0 supports new APIs for this purpose and these are to account for the threading model of WPF.

Continue reading "WPF and AppDomains" »

April 30, 2007

VSTS (Orcas Beta 1) Profiler - Comparing Performance Reports

In my earlier blog I had looked at March CTP of Orcas and talked about performance reports and performance comparison reports and raised a few issues.

I downloaded and started to play around with Orcas Beta 1 today and thought of checking the performance comparison report to start with. I ran the same code as I did earlier and compared the reports.

Continue reading "VSTS (Orcas Beta 1) Profiler - Comparing Performance Reports" »

April 23, 2007

LINQ and its linkage to new features in .NET Framework 3.5 – Part II,,,

In my previous blog “LINQ and its linkage to new features in .NET Framework 3.5 – Part I”, we have seen how a query can be expressed with clarity with object oriented programming notation and couple of code snippets that showed how a class can be extended through “extension” methods – a concept that is introduced in .NET Framework 3.5. It is really important to know that when the query gets executed at runtime. The following code snippet shows the usage of query expression.

IEnumerable<string> name = Names.OrderBy(s => s.Length)
                        .Where(s => s.Length >= 15)
                        .Select(s => s);

The query execution does not happen in this line of code, though it uses the assignment operation. Only when, looping is happening through the foreach statement of IEnumerable[] items, the query gets executed.

See the following code.

Continue reading "LINQ and its linkage to new features in .NET Framework 3.5 – Part II,,," »

April 19, 2007

LINQ and its linkage to new features in .NET Framework 3.5 – Part I,,,

Language Integrated Query (LINQ) related changes are going to be significant ones in .NET Framework 3.5 that is going to be released with next version of VS – code named Orcas. .NET Framework 3.5 enables the developers to use the managed languages (C# Version 3.0 and VB Version 9.0) to define the query on relational database, hierarchical infosets such as XML or .NET collection objects such as Arrays, in highly expressive manner. LINQ is meant to give the power to the mainstream development community in dealing with data on various sources, in consistent fashion within the domain of the managed languages using the familiar and flexible object oriented programming notations.

To get the taste of it, see the following code snippet, which queries the play’s titles that exceeds 14 characters in length.

Continue reading "LINQ and its linkage to new features in .NET Framework 3.5 – Part I,,," »