Show / Hide Table of Contents

Class MapConverter

An implementation of System.Windows.Data.IValueConverter that converts from one set of values to another based on the contents of the Mappings collection.

Inheritance
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
MapConverter
Implements
System.Windows.Data.IValueConverter
Inherited Members
System.Windows.DependencyObject.Equals(System.Object)
System.Windows.DependencyObject.GetHashCode()
System.Windows.DependencyObject.GetValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, System.Object)
System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey, System.Object)
System.Windows.DependencyObject.ClearValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.ClearValue(System.Windows.DependencyPropertyKey)
System.Windows.DependencyObject.CoerceValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty)
System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
System.Windows.DependencyObject.ShouldSerializeProperty(System.Windows.DependencyProperty)
System.Windows.DependencyObject.ReadLocalValue(System.Windows.DependencyProperty)
System.Windows.DependencyObject.GetLocalValueEnumerator()
System.Windows.DependencyObject.DependencyObjectType
System.Windows.DependencyObject.IsSealed
System.Windows.Threading.DispatcherObject.Dispatcher
System.Object.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: DevZest.Windows
Assembly: DevZest.WpfDocking.dll
Syntax
[ValueConversion(typeof(object), typeof(object))]
public class MapConverter : DependencyObject, IValueConverter
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:

<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>

The following example shows how a MapConverter can be used to convert between values of the System.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>

Fields

Name Description
FallbackBehaviorProperty

Identifies the FallbackBehavior dependency property.

Properties

Name Description
FallbackBehavior

Gets or sets the fallback behavior for this MapConverter. This is a dependency property.

Mappings

Gets the collection of Mapping objects configured for this MapConverter.

Methods

Name Description
Convert(Object, Type, Object, CultureInfo)

Converts source value to target value.

ConvertBack(Object, Type, Object, CultureInfo)

Converts target value to source value.

  • Improve this Doc
  • View Source
Back to top Copyright © Weifen Luo | DevZest