Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:wpf:data_binding [2012/12/03 18:12] smayr [ConverterParameter] |
swdev:dotnet:wpf:data_binding [2017/06/27 17:22] (current) smayr [Add Tracing to Output Window] |
||
---|---|---|---|
Line 19: | Line 19: | ||
Example: | Example: | ||
<code xml> | <code xml> | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
< | < | ||
- | < | + | |
</ | </ | ||
. . . | . . . | ||
Line 26: | Line 31: | ||
Visibility=" | Visibility=" | ||
Converter={StaticResource InstrumentSideDetectedToVisibilityConverter}, | Converter={StaticResource InstrumentSideDetectedToVisibilityConverter}, | ||
- | ConverterParameter={x: | + | ConverterParameter={x: |
Content=" | Content=" | ||
+ | . . . | ||
+ | </ | ||
</ | </ | ||
+ | |||
+ | Custom type declared in Acme.App.Types.dll assembly: | ||
+ | <code csharp> | ||
+ | public enum TSide | ||
+ | { | ||
+ | Left | ||
+ | Right | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Custom ValueConverter declared in Acme.App.ViewModel.dll assembly (view model): | ||
+ | <code csharp> | ||
+ | /// | ||
+ | /// < | ||
+ | /// Class TInstrumentSideDetectedToVisibilityConverter | ||
+ | /// </ | ||
+ | /// | ||
+ | public class TInstrumentSideDetectedToVisibilityConverter : IValueConverter | ||
+ | { | ||
+ | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
+ | { | ||
+ | Visibility _visibility; | ||
+ | |||
+ | if ( | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.Left) | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.Both) | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.None) | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.Right) && ((TSide)parameter == TSide.Right) || | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.Both) | ||
+ | ((TInstrumentDetectedResults)value == TInstrumentDetectedResults.None) | ||
+ | ) | ||
+ | { | ||
+ | _visibility = Visibility.Visible; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | _visibility = Visibility.Collapsed; | ||
+ | } | ||
+ | return _visibility; | ||
+ | } | ||
+ | |||
+ | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
+ | { | ||
+ | throw new NotImplementedException(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== UpdateSourceTrigger ==== | ==== UpdateSourceTrigger ==== | ||
To specify when the target property is updated. | To specify when the target property is updated. | ||
Line 221: | Line 275: | ||
<code xml> | <code xml> | ||
< | < | ||
- | < | + | < |
</ | </ | ||
</ | </ | ||
+ | |||
+ | Declaring a data source with parameters vs no parameters: | ||
+ | <code xml> | ||
+ | <!--Data Source--> | ||
+ | < | ||
+ | <!--This Method creates the object, then later it assigns the field (ie. field is not assign during construction)--> | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
Define the data type in library. | Define the data type in library. | ||
Line 236: | Line 305: | ||
public class TProductSpecificationList : List< | public class TProductSpecificationList : List< | ||
{ | { | ||
- | public TProductSpecificationList() | + | |
+ | |||
+ | // Parameterless Constructor | ||
+ | | ||
{ | { | ||
- | this.Add(" | + | |
- | this.Add(" | + | } |
+ | // Constructor with Parameters | ||
+ | public TProductSpecificationList(TCustomCompany aCustomCompany) | ||
+ | { | ||
+ | if (CustomCompany == TCustomCompany.Acme) | ||
+ | { | ||
+ | this.Add(" | ||
+ | | ||
+ | } | ||
} | } | ||
} | } | ||
Line 311: | Line 391: | ||
</ | </ | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | == Clearing Binding == | ||
+ | |||
+ | To clear data binding programmatically (for a '' | ||
+ | <code csharp> | ||
+ | BindingOperations.ClearBinding(txtName, | ||
</ | </ | ||
Line 1348: | Line 1435: | ||
= Debugging = | = Debugging = | ||
+ | |||
+ | == Add Tracing to Output Window == | ||
+ | |||
+ | 1. Add '' | ||
+ | <code xml> | ||
+ | <Window x: | ||
+ | xmlns=" | ||
+ | xmlns: | ||
+ | xmlns: | ||
+ | Title=" | ||
+ | < | ||
+ | < | ||
+ | diag: | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 2. Add a value converter to the binding, to be able to put a break point in debugger. | ||
+ | |||
+ | See more: | ||
+ | * [[https:// | ||
+ | |||
+ | == 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> | * Add a high TraceLevel to your binding: <code csharp> | ||
Line 1359: | Line 1469: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[https:// | ||
+ | |||
+ | |||
= See Also = | = See Also = | ||
* [[http:// | * [[http:// |