Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:wpf:data_binding [2013/02/18 16:59]
smayr [ObjectDataProvider]
swdev:dotnet:wpf:data_binding [2017/06/27 17:22] (current)
smayr [Add Tracing to Output Window]
Line 391: Line 391:
    </ListBox>    </ListBox>
 </Grid> </Grid>
 +</code>
 +
 +== Clearing Binding ==
 +
 +To clear data binding programmatically (for a ''TextBox'' called ''txtName''):
 +<code csharp>
 +BindingOperations.ClearBinding(txtName, TextBox.TextProperty);
 </code> </code>
  
Line 1428: Line 1435:
  
 = Debugging = = Debugging =
 +
 +== Add Tracing to Output Window ==
 +
 +1. Add ''diag:PresentationTraceSources.TraceLevel=High'' to your binding.  For example:
 +<code xml>
 +<Window x:Class="WpfApplication1.MainWindow"
 +        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 +        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 +        xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
 +        Title="MainWindow" Height="350" Width="525">
 +    <Grid>
 +        <TextBlock Text="{Binding ThereIsNoDataContext, 
 +            diag:PresentationTraceSources.TraceLevel=High}"/>
 +    </Grid>
 +</Window>
 +</code>
 +
 +2. Add a value converter to the binding, to be able to put a break point in debugger.
 +
 +See more:
 +  * [[https://spin.atomicobject.com/2013/12/11/wpf-data-binding-debug/|How To Debug Data Binding Issues in WPF]]
 +
 +== Enable Debug Output ==
   * Enable WPF debug output. In Visual Studio, Options > Debugging > Output Window > WPF Trace Settings > Data Binding > All.   * Enable WPF debug output. In Visual Studio, Options > Debugging > Output Window > WPF Trace Settings > Data Binding > All.
   * Add a high TraceLevel to your binding: <code csharp>PresentationTraceSources.SetTraceLevel(NewBinding, PresentationTraceLevel.High);</code>   * Add a high TraceLevel to your binding: <code csharp>PresentationTraceSources.SetTraceLevel(NewBinding, PresentationTraceLevel.High);</code>
Line 1439: Line 1469:
   * [[http://stackoverflow.com/questions/4026543/is-there-a-good-tool-for-debugging-xamls-databinding-behavior-errors-at-runtim|Tools for Debugging Data Binding at runtime]]   * [[http://stackoverflow.com/questions/4026543/is-there-a-good-tool-for-debugging-xamls-databinding-behavior-errors-at-runtim|Tools for Debugging Data Binding at runtime]]
   * [[http://bea.stollnitz.com/blog/?p=52|Bea Stollnitz: How can I debug WPF bindings?]]   * [[http://bea.stollnitz.com/blog/?p=52|Bea Stollnitz: How can I debug WPF bindings?]]
 +  * [[https://spin.atomicobject.com/2013/12/11/wpf-data-binding-debug/|How To Debug Data Binding Issues in WPF]]
 +
 +
 = See Also = = See Also =
   * [[http://msdn2.microsoft.com/en-us/library/ms752347(VS.85).aspx|MSDN Data Binding Overview]]   * [[http://msdn2.microsoft.com/en-us/library/ms752347(VS.85).aspx|MSDN Data Binding Overview]]