Created
July 29, 2023 01:41
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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