forked from dotnet/wpf
-
Notifications
You must be signed in to change notification settings - Fork 0
type convertor xaml shortening #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
himgoyalmicro
wants to merge
8
commits into
main
Choose a base branch
from
user/himgoyal/TypeConvertorXamlShortening
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c4f44e4
Intially Commit
himgoyalmicro fd9e3ee
RowDefinitionsChanges
himgoyalmicro 9cc2574
Merge branch 'dotnet:main' into user/himgoyal/TypeConvertorXamlShorte…
himgoyalmicro 604c290
PresentationFramework.cs changes
himgoyalmicro 16c5be4
Merge branch 'user/himgoyal/TypeConvertorXamlShortening' of https://g…
himgoyalmicro 1ce19a2
Creating new files for ColumnDefinitionCollectionConverter and RowDef…
himgoyalmicro bcd9848
Removing unnecessary changes
himgoyalmicro 3add783
Resolving Comments
himgoyalmicro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
.../src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| // | ||
| // | ||
| // | ||
| // Description: Contains the ColumnDefinitionCollectionConverter: TypeConverter for the ColumnDefinitionCollection. | ||
| // | ||
| // | ||
|
|
||
| using MS.Internal; | ||
| using MS.Internal.Controls; | ||
| using MS.Internal.PresentationFramework; | ||
| using MS.Internal.Telemetry.PresentationFramework; | ||
| using MS.Utility; | ||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics; | ||
| using System.Windows.Threading; | ||
| using System.Threading; | ||
| using System.Windows; | ||
| using System.Windows.Controls; | ||
| using System.Windows.Documents; | ||
| using System.Windows.Media; | ||
| using System.Windows.Markup; | ||
| using System.Globalization; | ||
himgoyalmicro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #pragma warning disable 1634, 1691 // suppressing PreSharp warnings | ||
|
|
||
| namespace System.Windows.Controls | ||
| { | ||
|
|
||
| public class ColumnDefinitionCollectionConverter : TypeConverter | ||
| { | ||
| #region Public Methods | ||
|
|
||
| /// <summary> | ||
| /// CanConvertFrom - Returns whether or not this class can convert from a given type. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// bool - True if thie converter can convert from the provided type, false if not. | ||
| /// </returns> | ||
| /// <param name="context"> The ITypeDescriptorContext for this call. </param> | ||
| /// <param name="sourceType"> The Type being queried for support. </param> | ||
| public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
| { | ||
| return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// CanConvertTo - Returns whether or not this class can convert to a given type. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// bool - True if this converter can convert to the provided type, false if not. | ||
| /// </returns> | ||
| /// <param name="context"> The ITypeDescriptorContext for this call. </param> | ||
| /// <param name="destinationType"> The Type being queried for support. </param> | ||
| public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) | ||
| { | ||
| return destinationType == typeof(string) || base.CanConvertTo(context, destinationType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// ConvertFrom - Attempt to convert to a ColumnDefinitionCollection from the given object. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// The object which was constructoed. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// An ArgumentNullException is thrown if the example object is null. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentException"> | ||
| /// An ArgumentException is thrown if the object is not null and is not a valid type, | ||
| /// or if the destinationType isn't one of the valid destination types. | ||
| /// </exception> | ||
| /// <param name="context"> The ITypeDescriptorContext for this call. </param> | ||
| /// <param name="culture"> The CultureInfo which is respected when converting. </param> | ||
| /// <param name="value"> The Thickness to convert. </param> | ||
| public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
| { | ||
| if (value is string input) | ||
| { | ||
| IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; | ||
| Grid grid = ipvt?.TargetObject as Grid; | ||
| if(grid != null) | ||
| { | ||
| var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance | ||
| var converter = new GridLengthConverter(); | ||
|
|
||
| foreach (var length in input.Split(',')) | ||
| { | ||
| if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) | ||
| { | ||
| collection.Add(new ColumnDefinition { Width = gridLength }); | ||
| } | ||
| } | ||
| return collection; | ||
| } | ||
| } | ||
|
|
||
| return base.ConvertFrom(context, culture, value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// ConvertTo - Attempt to convert a ColumnDefinitionCollection to the given type | ||
| /// </summary> | ||
| /// <returns> | ||
| /// The object which was constructoed. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// An ArgumentNullException is thrown if the example object is null. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentException"> | ||
| /// An ArgumentException is thrown if the object is not null and is not a Thickness, | ||
| /// or if the destinationType isn't one of the valid destination types. | ||
| /// </exception> | ||
| /// <param name="context"> The ITypeDescriptorContext for this call. </param> | ||
| /// <param name="culture"> The CultureInfo which is respected when converting. </param> | ||
| /// <param name="value"> The ColumnDefintionCollection to convert. </param> | ||
| /// <param name="destinationType">The type to which to convert the ColumnDefintionCollection instance. </param> | ||
| public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
| { | ||
| if (destinationType == typeof(string) && value is ColumnDefinitionCollection columnDefinitions) | ||
| { | ||
| var parts = new string[columnDefinitions.Count]; | ||
|
|
||
| for (int i = 0; i < columnDefinitions.Count; i++) | ||
| { | ||
| parts[i] = columnDefinitions[i].Width.ToString(); | ||
| } | ||
|
|
||
| return string.Join(",", parts); | ||
| } | ||
|
|
||
| return base.ConvertTo(context, culture, value, destinationType); | ||
| } | ||
|
|
||
| #endregion Public Methods | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.