MapConverter Class

DevZest WPF Docking

MapConverter Class
An implementation of IValueConverter that converts from one set of values to another based on the contents of the Mappings collection.
Inheritance Hierarchy

Namespace: DevZest.Windows
Assembly: DevZest.WpfDocking (in DevZest.WpfDocking.dll) Version: 2.5.0.0 (2.5.5912.0)
Syntax
[ContentPropertyAttribute("Mappings")]
[ValueConversionAttribute(typeof(Object), typeof(Object))]
public class MapConverter : DependencyObject, 
	IValueConverter
<ContentPropertyAttribute("Mappings")>
<ValueConversionAttribute(GetType(Object), GetType(Object))>
Public Class MapConverter
	Inherits DependencyObject
	Implements IValueConverter

The MapConverter type exposes the following members.

Constructors
  NameDescription
Public methodMapConverter
Initializes a new instance of the MapConverter class
Top
Properties
  NameDescription
Public propertyFallbackBehavior
Gets or sets the fallback behavior for this MapConverter. This is a dependency property.
Public propertyMappings
Gets the collection of Mapping objects configured for this MapConverter.
Top
Methods
  NameDescription
Public methodConvert
Converts source value to target value.
Public methodConvertBack
Converts target value to source value.
Top
Fields
  NameDescription
Public fieldStatic memberFallbackBehaviorProperty
Identifies the FallbackBehavior dependency property.
Top
Remarks

The MapConverter converts from one set of values to another. The source and destination values are stored in instances of Mapping inside the Mappings collection.

If this converter is asked to convert a value for which it has no knowledge, it will use the FallbackBehavior to determine how to deal with the situation.

Examples
The following example shows a MapConverter being used to control the visibility of a Label based on a CheckBox:
XAML
<CheckBox x:Name="_checkBox"/>
<Label Content="Here is the label.">
  <Label.Visibility>
    <Binding Path="IsChecked" ElementName="_checkBox" FallbackValue="Collapsed">
      <Binding.Converter>
        <MapConverter>
          <Mapping To="{x:Static Visibility.Visible}">
            <Mapping.From>
              <sys:Boolean>True</sys:Boolean>
            </Mapping.From>
          </Mapping>
        </MapConverter>
      </Binding.Converter>
    </Binding>
  </Label.Visibility>
</Label>
Examples
The following example shows how a MapConverter can be used to convert between values of the UriFormat enumeration and human-readable strings. Notice how not all possible values are present in the mappings. The fallback behavior is set to ReturnOriginalValue to ensure that any conversion failures result in the original value being returned:
<Label>
  <Label.Content>
    <Binding Path="UriFormat">
      <Binding.Converter>
        <MapConverter FallbackBehavior="ReturnOriginalValue">
          <Mapping From="{x:Static sys:UriFormat.SafeUnescaped}" To="Safe unescaped"/>
          <Mapping From="{x:Static sys:UriFormat.UriEscaped}" To="URI escaped"/>
        </MapConverter>
      </Binding.Converter>
    </Binding>
  </Label.Content>
</Label>
See Also