Mono.Xaml.MarkupExpressionParser.HandleProperty C# (CSharp) Méthode

HandleProperty() private méthode

private HandleProperty ( Binding b, string prop, string &remaining ) : void
b System.Windows.Data.Binding
prop string
remaining string
Résultat void
		private void HandleProperty (Binding b, string prop, ref string remaining)
		{
			char next;
			object value = null;
			string str_value = null;

			if (remaining.StartsWith ("{")) {
				value = ParseExpression (ref remaining);
				remaining = remaining.TrimStart ();

				if (remaining.Length > 0 && remaining[0] == ',')
					remaining = remaining.Substring (1);

				if (value is string)
					str_value = (string) value;
			}
			else {
				str_value = GetNextPiece (ref remaining, out next);
			}

			switch (prop) {
			case "FallbackValue":
				b.FallbackValue = value ?? str_value;
				break;
			case "Mode":
				if (str_value == null)
					throw new XamlParseException (String.Format ("Invalid type '{0}' for Mode.", value == null ? "null" : value.GetType ().ToString ()));
				b.Mode = (BindingMode) Enum.Parse (typeof (BindingMode), str_value, true);
				break;
			case "Path":
				if (str_value == null)
					throw new XamlParseException (String.Format ("Invalid type '{0}' for Path.", value == null ? "null" : value.GetType ().ToString ()));
				b.Path = new PropertyPath (str_value);
				break;
			case "Source":
				// if the expression was: Source="{StaticResource xxx}" then 'value' will be populated
				// If the expression was  Source="5" then 'str_value' will be populated.
				b.Source = value ?? str_value;
				break;
			case "StringFormat":
				b.StringFormat = (string) value ?? str_value;
				break;
			case "Converter":
				IValueConverter value_converter = value as IValueConverter;
				if (value_converter == null && value != null)
					throw new Exception ("A Binding Converter must be of type IValueConverter.");
				b.Converter = value_converter;
				break;
			case "ConverterParameter":
				b.ConverterParameter = value ?? str_value;
				break;
			case "NotifyOnValidationError":
				bool bl;
				if (!Boolean.TryParse (str_value, out bl))
					throw new Exception (String.Format ("Invalid value {0} for NotifyValidationOnError.", str_value));
				b.NotifyOnValidationError = bl;
				break;
			case "TargetNullValue":
				b.TargetNullValue = value ?? str_value;
				break;
			case "ValidatesOnExceptions":
				if (!Boolean.TryParse (str_value, out bl))
					throw new Exception (String.Format ("Invalid value {0} for ValidatesOnExceptions.", str_value));
				b.ValidatesOnExceptions = bl;
				break;
			case "ValidatesOnDataErrors":
				if (!bool.TryParse (str_value, out bl))
					throw new Exception (string.Format ("Invalid value {0} for ValidatesOnDataErrors", str_value));
				b.ValidatesOnDataErrors = bl;
				break;
			case "ValidatesOnNotifyDataErrors":
				if (!bool.TryParse (str_value, out bl))
					throw new Exception (string.Format ("Invalid value {0} for ValidatesOnNotifyDataErrors", str_value));
				b.ValidatesOnNotifyDataErrors = bl;
				break;
			case "RelativeSource":
				RelativeSource rs = value as RelativeSource;
				if (rs == null)
					throw new Exception (String.Format ("Invalid value {0} for RelativeSource.", value));
				 b.RelativeSource = rs;
				break;
			case "ElementName":
				b.ElementName = (string) value ?? str_value;
				break;
			case "UpdateSourceTrigger":
				b.UpdateSourceTrigger = (UpdateSourceTrigger) Enum.Parse (typeof (UpdateSourceTrigger), str_value, true);
				break;
			default:
				Console.Error.WriteLine ("Unhandled Binding Property:  '{0}'  value:  {1}", prop, value != null ? value.ToString () : str_value);
				break;
			}
		}