Skip to content

Instantly share code, notes, and snippets.

@nilsandrey
Created July 29, 2023 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsandrey/f79cd41eb7ad05070bb7dd5da06f562f to your computer and use it in GitHub Desktop.
Save nilsandrey/f79cd41eb7ad05070bb7dd5da06f562f to your computer and use it in GitHub Desktop.
Use a ValueConverter to break into the debugger when having Debug Databinding Issues in WPF. (From: http://www.wpftutorial.net/DebugDataBinding.html)
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Data;
/// <summary>
/// This converter does nothing except breaking the
/// debugger into the convert method
/// </summary>
public class DatabindingDebugConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
Debugger.Break();
return value;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
Debugger.Break();
return value;
}
}
<Window x:Class="DebugDataBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DebugDataBinding"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:DatabindingDebugConverter x:Key="debugConverter" />
</Window.Resources>
<StackPanel x:Name="stack">
<TextBlock Text="{Binding ElementName=stack, Path=ActualWidth,
Converter={StaticResource debugConverter}}" />
</StackPanel>
</Window>
<mycontrol:mycontrolBase
x:Class="My.Project.View"
...
xmlns:converters1="clr-namespace:RQ.Windows.Converters"
...>
...
<TextBlock Text="{Binding DataContext.ShowTaxApplicationTypes, Source={StaticResource Spy}, Converter={x:Static converters1:DatabindingDebugConverter.Instance}}" />
...
</mycontrol:mycontrolBase>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment