public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (value != null && value is GridLength) { GridLength gl = (GridLength)value; if (destinationType == typeof(string)) { return(GridLengthConverter.ToString(gl, cultureInfo)); } if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo constructor = typeof(GridLength).GetConstructor(new Type[] { typeof(double), typeof(GridUnitType) }); return(new InstanceDescriptor(constructor, new object[] { gl.Value, gl.GridUnitType })); } } throw base.GetConvertToException(value, destinationType); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double val = (double)value; GridLengthConverter GLConverter = new GridLengthConverter(); GridLength gridLength = (GridLength)(GLConverter.ConvertFromString (val.ToString() + "*")); return gridLength; }
private void r180_Click(object sender, RoutedEventArgs e) { if (beforeRotate != 180) { ArcadeMenu.Display.Rotate(1, Display.Orientations.DEGREES_CW_180); var gridLengthConverter = new System.Windows.GridLengthConverter(); string ww = (this.Width / 4).ToString(); colwidth.Width = (GridLength)gridLengthConverter.ConvertFromString(ww); beforeRotate = 180; } }
public MainWindow() { InitializeComponent(); this.WindowStyle = WindowStyle.None; this.BringIntoView(); this.Topmost = true; //Get Current Rotation int i = ArcadeMenu.Display.GetCurrentRotate(1); //Sizing tiles to monitor if (i == 3) { var gridLengthConverter1 = new System.Windows.GridLengthConverter(); string ww1 = (this.Width / 20).ToString(); colwidth.Width = (GridLength)gridLengthConverter1.ConvertFromString(ww1); beforeRotate = 270; } if (i == 1) { var gridLengthConverter2 = new System.Windows.GridLengthConverter(); string ww2 = (this.Width / 20).ToString(); colwidth.Width = (GridLength)gridLengthConverter2.ConvertFromString(ww2); beforeRotate = 90; } if (i == 2) { var gridLengthConverter3 = new System.Windows.GridLengthConverter(); string ww3 = (this.Width / 4).ToString(); colwidth.Width = (GridLength)gridLengthConverter3.ConvertFromString(ww3); beforeRotate = 180; } if (i == 0) { var gridLengthConverter = new System.Windows.GridLengthConverter(); string ww = (this.Width / 4).ToString(); colwidth.Width = (GridLength)gridLengthConverter.ConvertFromString(ww); beforeRotate = 0; } //MessageBox.Show(i.ToString()); //Defaults on startup // beforeRotate = ArcadeMenu.Display.GetCurrentRotate(1); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); this.WindowState = WindowState.Maximized; }
/// <summary> /// Create a grid length from a string, consistently in WPF, WP7 and SL. /// </summary> /// <param name="gridLength">The grid length, e.g. 4*, Auto, 23 etc.</param> /// <returns>A gridlength.</returns> public GridLength ConvertFromString(string gridLength) { // If we're NOT in silverlight, we have a gridlength converter // we can use. #if !SILVERLIGHT // Create the standard windows grid length converter. var gridLengthConverter = new System.Windows.GridLengthConverter(); // Return the converted grid length. return((GridLength)gridLengthConverter.ConvertFromString(gridLength)); #else // We are in silverlight and do not have a grid length converter. // We can do the conversion by hand. // Auto is easy. if (gridLength == "Auto") { return(new GridLength(1, GridUnitType.Auto)); } else if (gridLength.Contains("*")) { // It's a starred value, remove the star and get the coefficient as a double. double coefficient = 1; string starVal = gridLength.Replace("*", ""); // If there is a coefficient, try and convert it. // If we fail, throw an exception. if (starVal.Length > 0 && double.TryParse(starVal, out coefficient) == false) { throw new Exception("'" + gridLength + "' is not a valid value."); } // We've handled the star value. return(new GridLength(coefficient, GridUnitType.Star)); } else { // It's not auto or star, so unless it's a plain old pixel // value we must throw an exception. double pixelVal = 0; if (double.TryParse(gridLength, out pixelVal) == false) { throw new Exception("'" + gridLength + "' is not a valid value."); } // We've handled the star value. return(new GridLength(pixelVal, GridUnitType.Pixel)); } #endif }
/// <summary> /// Create a grid length from a string, consistently in WPF, WP7 and SL. /// </summary> /// <param name="gridLength">The grid length, e.g. 4*, Auto, 23 etc.</param> /// <returns>A grid length.</returns> public GridLength ConvertFromString(string gridLength) { // If we're NOT in silverlight, we have a gridlength converter // we can use. #if !SILVERLIGHT && !NETFX_CORE // Create the standard windows grid length converter. var gridLengthConverter = new System.Windows.GridLengthConverter(); // Return the converted grid length. return (GridLength)gridLengthConverter.ConvertFromString(gridLength); #else // We are in silverlight and do not have a grid length converter. // We can do the conversion by hand. // Auto is easy. if (gridLength == "Auto") { return new GridLength(1, GridUnitType.Auto); } // if if (gridLength.Contains("*")) { // It's a starred value, remove the star and get the coefficient as a double. double coefficient = 1; var starVal = gridLength.Replace("*", string.Empty); // If there is a coefficient, try and convert it. // If we fail, throw an exception. if (starVal.Length > 0 && double.TryParse(starVal, out coefficient) == false) { throw new Exception("'" + gridLength + "' is not a valid value."); } // if // We've handled the star value. return new GridLength(coefficient, GridUnitType.Star); } // if // It's not auto or star, so unless it's a plain old pixel // value we must throw an exception. double pixelVal; if (double.TryParse(gridLength, out pixelVal) == false) { throw new Exception("'" + gridLength + "' is not a valid value."); } // if // We've handled the star value. return new GridLength(pixelVal, GridUnitType.Pixel); #endif } // ConvertFromString
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var gridLengthConverter = new GridLengthConverter(); var gridLengthRaw = gridLengthConverter.ConvertFrom(parameter); if (gridLengthRaw == null) throw new ArgumentException("Parameter must be convertable to GridLength"); var defaultGridLength = (GridLength)gridLengthRaw; var boolValue = (bool) value; return boolValue ? defaultGridLength : new GridLength(0); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param> /// <param name="value">The <see cref="T:System.Object" /> to convert.</param> /// <returns> /// An <see cref="T:System.Object" /> that represents the converted value. /// </returns> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed.</exception> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var s = value as string; if (s != null) { var glc = new GridLengthConverter(); var c = new List<GridLength>(); foreach (var item in s.Split(SplitterChars)) { c.Add((GridLength)glc.ConvertFrom(item)); } return c; } return base.ConvertFrom(context, culture, value); }
public Main() { InitializeComponent(); var userPrefs = new UserPreferences(); GridLengthConverter myGridLengthConverter = new GridLengthConverter(); GridLength gl1 = (GridLength)myGridLengthConverter.ConvertFromString(userPrefs.WindowLeftColumn.ToString()); this.columnLeft.Width = gl1; gl1 = (GridLength)myGridLengthConverter.ConvertFromString(userPrefs.WindowRightColumn.ToString()); this.columnRight.Width = gl1; this.F1.AddHandler(Favorites.TargetSetClick, new RoutedEventHandler(this.TargetSetClickHandler)); this.F1.AddHandler(Favorites.FavoriteClick, new RoutedEventHandler(this.FavoriteClickEventHandler)); this.T1.AddHandler(TreeExplorer.PopulateEverything, new RoutedEventHandler(this.PopulateEverythingHandler)); this.T1.AddHandler(TreeExplorer.TargetDoubleClick, new RoutedEventHandler(this.TargetDoubleClickHandler)); this.T1.AddHandler(TreeExplorer.TargetClick, new RoutedEventHandler(this.TargetClickHandler)); this.T1.AddHandler(TreeExplorer.StartExplore, new RoutedEventHandler(this.StartExploreHandler)); this.T1.AddHandler(TreeExplorer.FinishedExplore, new RoutedEventHandler(this.FinishedExploreHandler)); this.T1.AddHandler(TreeExplorer.FailedExplore, new RoutedEventHandler(this.FailedExploreHandler)); }
/// <summary>Attempts to convert a specified object to an instance of <see cref="T:System.Windows.GridLength" />. </summary> /// <param name="typeDescriptorContext">Describes the context information of a type.</param> /// <param name="cultureInfo">Cultural specific information that should be respected during conversion.</param> /// <param name="source">The object being converted.</param> /// <returns>The instance of <see cref="T:System.Windows.GridLength" /> that is created from the converted <paramref name="source" />.</returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source" /> object is <see langword="null" />.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="source" /> object is not <see langword="null" /> and is not a valid type that can be converted to a <see cref="T:System.Windows.GridLength" />.</exception> // Token: 0x06000728 RID: 1832 RVA: 0x00016A10 File Offset: 0x00014C10 public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { if (source == null) { throw base.GetConvertFromException(source); } if (source is string) { return(GridLengthConverter.FromString((string)source, cultureInfo)); } double value = Convert.ToDouble(source, cultureInfo); GridUnitType type; if (DoubleUtil.IsNaN(value)) { value = 1.0; type = GridUnitType.Auto; } else { type = GridUnitType.Pixel; } return(new GridLength(value, type)); }
// Initialize known object types internal static TypeConverter CreateKnownTypeConverter(Int16 converterId) { TypeConverter o = null; switch (converterId) { case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break; case -46: o = new System.ComponentModel.BooleanConverter(); break; case -53: o = new System.Windows.Media.BrushConverter(); break; case -61: o = new System.ComponentModel.ByteConverter(); break; case -70: o = new System.ComponentModel.CharConverter(); break; case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; case -87: o = new System.Windows.Media.ColorConverter(); break; case -94: o = new System.Windows.Input.CommandConverter(); break; case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; case -111: o = new System.Windows.CornerRadiusConverter(); break; case -114: o = new System.ComponentModel.CultureInfoConverter(); break; case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break; case -117: o = new System.Windows.Input.CursorConverter(); break; case -124: o = new System.ComponentModel.DateTimeConverter(); break; case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; case -130: o = new System.ComponentModel.DecimalConverter(); break; case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; case -138: o = new System.Windows.DialogResultConverter(); break; case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break; case -175: o = new System.ComponentModel.DoubleConverter(); break; case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break; case -188: o = new System.Windows.DurationConverter(); break; case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break; case -201: o = new System.Windows.ExpressionConverter(); break; case -204: o = new System.Windows.FigureLengthConverter(); break; case -215: o = new System.Windows.Media.FontFamilyConverter(); break; case -216: o = new System.Windows.FontSizeConverter(); break; case -218: o = new System.Windows.FontStretchConverter(); break; case -220: o = new System.Windows.FontStyleConverter(); break; case -222: o = new System.Windows.FontWeightConverter(); break; case -240: o = new System.Windows.Media.GeometryConverter(); break; case -256: o = new System.Windows.GridLengthConverter(); break; case -267: o = new System.ComponentModel.GuidConverter(); break; case -286: o = new System.Windows.Media.ImageSourceConverter(); break; case -299: o = new System.Windows.Input.InputScopeConverter(); break; case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; case -306: o = new System.ComponentModel.Int16Converter(); break; case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; case -315: o = new System.ComponentModel.Int32Converter(); break; case -319: o = new System.Windows.Int32RectConverter(); break; case -324: o = new System.ComponentModel.Int64Converter(); break; case -338: o = new System.Windows.Input.KeyConverter(); break; case -340: o = new System.Windows.Input.KeyGestureConverter(); break; case -342: o = new System.Windows.KeySplineConverter(); break; case -344: o = new System.Windows.KeyTimeConverter(); break; case -348: o = new System.Windows.LengthConverter(); break; case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; case -392: o = new System.Windows.Media.MatrixConverter(); break; case -410: o = new System.Windows.Input.ModifierKeysConverter(); break; case -411: o = new System.Windows.Input.MouseActionConverter(); break; case -415: o = new System.Windows.Input.MouseGestureConverter(); break; case -423: o = new System.Windows.NullableBoolConverter(); break; case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; case -453: o = new System.Windows.Media.PixelFormatConverter(); break; case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break; case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break; case -473: o = new System.Windows.Media.PointCollectionConverter(); break; case -474: o = new System.Windows.PointConverter(); break; case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; case -492: o = new System.Windows.PropertyPathConverter(); break; case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; case -511: o = new System.Windows.RectConverter(); break; case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; case -538: o = new System.Windows.Markup.RoutedEventConverter(); break; case -545: o = new System.ComponentModel.SByteConverter(); break; case -563: o = new System.ComponentModel.SingleConverter(); break; case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; case -572: o = new System.Windows.SizeConverter(); break; case -615: o = new System.ComponentModel.StringConverter(); break; case -619: o = new System.Windows.StrokeCollectionConverter(); break; case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break; case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break; case -645: o = new System.Windows.TextDecorationCollectionConverter(); break; case -655: o = new System.Windows.ThicknessConverter(); break; case -664: o = new System.ComponentModel.TimeSpanConverter(); break; case -681: o = new System.Windows.Media.TransformConverter(); break; case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; case -696: o = new System.ComponentModel.UInt16Converter(); break; case -698: o = new System.ComponentModel.UInt32Converter(); break; case -700: o = new System.ComponentModel.UInt64Converter(); break; case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break; case -705: o = new System.UriTypeConverter(); break; case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break; case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; case -722: o = new System.Windows.Media.VectorCollectionConverter(); break; case -723: o = new System.Windows.VectorConverter(); break; case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; } return o; }
/// <summary>Returns a <see cref="T:System.String" /> representation of the <see cref="T:System.Windows.GridLength" />.</summary> /// <returns>A <see cref="T:System.String" /> representation of the current <see cref="T:System.Windows.GridLength" /> structure.</returns> // Token: 0x06000723 RID: 1827 RVA: 0x000169BB File Offset: 0x00014BBB public override string ToString() { return(GridLengthConverter.ToString(this, CultureInfo.InvariantCulture)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var converter = new System.Windows.GridLengthConverter(); return(converter.ConvertFrom(value)); }
public GridLengthConverter() { internalGridLengthConverter = new InternalGridLengthConverter(); }
/// <summary> /// Sets the attribute. /// </summary> /// <param name="attribute">The attribute.</param> /// <param name="pi">The pi.</param> /// <param name="instance">The instance.</param> protected virtual void SetAttribute(Attribute attribute, PropertyItem pi, object instance) { var ssa = attribute as SelectorStyleAttribute; if (ssa != null) { pi.SelectorStyle = ssa.SelectorStyle; } var svpa = attribute as SelectedValuePathAttribute; if (svpa != null) { pi.SelectedValuePath = svpa.Path; } var f = attribute as FontAttribute; if (f != null) { pi.FontSize = f.FontSize; pi.FontWeight = f.FontWeight; pi.FontFamily = f.FontFamily; } var fp = attribute as FontPreviewAttribute; if (fp != null) { pi.PreviewFonts = true; pi.FontSize = fp.Size; pi.FontWeight = fp.Weight; pi.FontFamilyPropertyDescriptor = pi.GetDescriptor(fp.FontFamilyPropertyName); } if (attribute is FontFamilySelectorAttribute) { pi.IsFontFamilySelector = true; } var ifpa = attribute as InputFilePathAttribute; if (ifpa != null) { pi.IsFilePath = true; pi.IsFileOpenDialog = true; pi.FilePathFilter = ifpa.Filter; pi.FilePathDefaultExtension = ifpa.DefaultExtension; } var ofpa = attribute as OutputFilePathAttribute; if (ofpa != null) { pi.IsFilePath = true; pi.IsFileOpenDialog = false; pi.FilePathFilter = ofpa.Filter; pi.FilePathDefaultExtension = ofpa.DefaultExtension; } if (attribute is DirectoryPathAttribute) { pi.IsDirectoryPath = true; } var da = attribute as DataTypeAttribute; if (da != null) { pi.DataTypes.Add(da.DataType); switch (da.DataType) { case DataType.MultilineText: pi.AcceptsReturn = true; break; case DataType.Password: pi.IsPassword = true; break; } } var ca = attribute as ColumnAttribute; if (ca != null) { var glc = new GridLengthConverter(); var cd = new ColumnDefinition { PropertyName = ca.PropertyName, Header = ca.Header, FormatString = ca.FormatString, Width = (GridLength)(glc.ConvertFromInvariantString(ca.Width) ?? GridLength.Auto), IsReadOnly = ca.IsReadOnly, HorizontalAlignment = StringUtilities.ToHorizontalAlignment(ca.Alignment.ToString(CultureInfo.InvariantCulture)) }; // TODO: sort by index pi.Columns.Add(cd); } var la = attribute as ListAttribute; if (la != null) { pi.ListCanAdd = la.CanAdd; pi.ListCanRemove = la.CanRemove; pi.ListMaximumNumberOfItems = la.MaximumNumberOfItems; } var ida = attribute as InputDirectionAttribute; if (ida != null) { pi.InputDirection = ida.InputDirection; } var eia = attribute as EasyInsertAttribute; if (eia != null) { pi.EasyInsert = eia.EasyInsert; } var sia = attribute as SortIndexAttribute; if (sia != null) { pi.SortIndex = sia.SortIndex; } var eba = attribute as EnableByAttribute; if (eba != null) { pi.IsEnabledDescriptor = pi.GetDescriptor(eba.PropertyName); pi.IsEnabledValue = eba.PropertyValue; } var vba = attribute as VisibleByAttribute; if (vba != null) { pi.IsVisibleDescriptor = pi.GetDescriptor(vba.PropertyName); pi.IsVisibleValue = vba.PropertyValue; } var oa = attribute as OptionalAttribute; if (oa != null) { pi.IsOptional = true; if (oa.PropertyName != null) { pi.OptionalDescriptor = pi.GetDescriptor(oa.PropertyName); } } var ila = attribute as IndentationLevelAttribute; if (ila != null) { pi.IndentationLevel = ila.IndentationLevel; } var ra = attribute as EnableByRadioButtonAttribute; if (ra != null) { pi.RadioDescriptor = pi.GetDescriptor(ra.PropertyName); pi.RadioValue = ra.Value; } if (attribute is CommentAttribute) { pi.IsComment = true; } if (attribute is ContentAttribute) { pi.IsContent = true; } var ea = attribute as EditableAttribute; if (ea != null) { pi.IsEditable = ea.AllowEdit; } if (attribute is AutoUpdateTextAttribute) { pi.AutoUpdateText = true; } var ispa = attribute as ItemsSourcePropertyAttribute; if (ispa != null) { pi.ItemsSourceDescriptor = pi.GetDescriptor(ispa.PropertyName); } var liispa = attribute as ListItemItemsSourcePropertyAttribute; if (liispa != null) { var p = TypeDescriptor.GetProperties(instance)[liispa.PropertyName]; var listItemItemsSource = p != null ? p.GetValue(instance) as IEnumerable : null; pi.ListItemItemsSource = listItemItemsSource; } var clpa = attribute as CheckableItemsAttribute; if (clpa != null) { pi.CheckableItemsIsCheckedPropertyName = clpa.IsCheckedPropertyName; pi.CheckableItemsContentPropertyName = clpa.ContentPropertyName; } var rpa = attribute as BasePathPropertyAttribute; if (rpa != null) { pi.RelativePathDescriptor = pi.GetDescriptor(rpa.BasePathPropertyName); } var fa = attribute as FilterPropertyAttribute; if (fa != null) { pi.FilterDescriptor = pi.GetDescriptor(fa.PropertyName); } var dea = attribute as DefaultExtensionPropertyAttribute; if (dea != null) { pi.DefaultExtensionDescriptor = pi.GetDescriptor(dea.PropertyName); } var fsa = attribute as FormatStringAttribute; if (fsa != null) { pi.FormatString = fsa.FormatString; } var coa = attribute as ConverterAttribute; if (coa != null) { pi.Converter = Activator.CreateInstance(coa.ConverterType) as IValueConverter; } var sa = attribute as SlidableAttribute; if (sa != null) { pi.IsSlidable = true; pi.SliderMinimum = sa.Minimum; pi.SliderMaximum = sa.Maximum; pi.SliderSmallChange = sa.SmallChange; pi.SliderLargeChange = sa.LargeChange; pi.SliderSnapToTicks = sa.SnapToTicks; pi.SliderTickFrequency = sa.TickFrequency; } var spa = attribute as SpinnableAttribute; if (spa != null) { pi.IsSpinnable = true; pi.SpinMinimum = spa.Minimum; pi.SpinMaximum = spa.Maximum; pi.SpinSmallChange = spa.SmallChange; pi.SpinLargeChange = spa.LargeChange; } var wpa = attribute as WidePropertyAttribute; if (wpa != null) { pi.HeaderPlacement = wpa.ShowHeader ? HeaderPlacement.Above : HeaderPlacement.Hidden; } var wia = attribute as WidthAttribute; if (wia != null) { pi.Width = wia.Width; } var hpa = attribute as HeaderPlacementAttribute; if (hpa != null) { pi.HeaderPlacement = hpa.HeaderPlacement; } var ha = attribute as HorizontalAlignmentAttribute; if (ha != null) { pi.HorizontalAlignment = ha.HorizontalAlignment; } var hea = attribute as HeightAttribute; if (hea != null) { pi.Height = hea.Height; pi.MinimumHeight = hea.MinimumHeight; pi.MaximumHeight = hea.MaximumHeight; pi.AcceptsReturn = true; } var fta = attribute as FillTabAttribute; if (fta != null) { pi.FillTab = true; pi.AcceptsReturn = true; } }