Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / WPF
Tip/Trick

Using a TestValueConverter to Understand a Bound Object

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
21 Nov 2015CPOL 15.9K   5  
Using a breakpoint in this WPF Value Converter which basically does nothing can be of assistance in binding when the object is not well understood.

Introduction

I have had many cases when I have worked with third party controls from companies such as Infragistics and Telerik, and have wanted to create some functionality, and have not known enough about the objects I am using to be able to do it. These objects can be extremely complex, which actually can be very good since there is a lot of data that can be tapped to accomplish some special functionality. This also makes them difficult to understand, and there is little on the internet about them. Since these controls are not visible in the normal debugger, I have bound a value to a simple IValueConverter and inserted a breakpoint in the converter so that I could investigate the data that I am bound to. This has allowed to then refine the binding, and create the functionality I need. I have also used this converter when I did not understand why the binding was not working correctly.

The Code

C#
#region using statements

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

#endregion

public sealed class TestConverter : MarkupExtension, IValueConverter
{
    public TestConverter() { }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }

    public override object ProvideValue(IServiceProvider serviceProvider) { return this; }
}

History

  • 11/21/2015 Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Clifford Nelson Consulting
United States United States
Has been working as a C# developer on contract for the last several years, including 3 years at Microsoft. Previously worked with Visual Basic and Microsoft Access VBA, and have developed code for Word, Excel and Outlook. Started working with WPF in 2007 when part of the Microsoft WPF team. For the last eight years has been working primarily as a senior WPF/C# and Silverlight/C# developer. Currently working as WPF developer with BioNano Genomics in San Diego, CA redesigning their UI for their camera system. he can be reached at qck1@hotmail.com.

Comments and Discussions

 
-- There are no messages in this forum --