-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Pin properties dev tool update #12315
Pin properties dev tool update #12315
Conversation
You can test this PR using the following package version. |
I would put both regulat and attached pinned properties in a new group in the same DataGrid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR, I didn't have time to do it at the time. I don't like the solution of the two headers very much because it increases the complexity. To fix you could just add one more grouping (Pinned/Unpinned) with collapsible.
@@ -4161,7 +4161,7 @@ void SetValidationStatus(ICellEditBinding binding) | |||
|
|||
ResetValidationStatus(); | |||
|
|||
if (exitEditingMode) | |||
if (exitEditingMode && CurrentColumn != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change should be included in a separate PR where the reason of change is explained.
Do you mean something like Or more like what is shown here? https://www.c-sharpcorner.com/uploadfile/dpatra/grouping-in-datagrid-in-wpf/ I could also just simply add another groupdescription for IsPinned but, that will not achieve the effect of having the pinned properties always visible while scrolling through non-pinned properties and users would have to scroll back to the top to see them. And no worries, I enjoy doing it! |
This |
Group description you mean? I can get that pushed shortly! |
@workgroupengineering @robloo I think i've addressed all concerns with the most recent commit |
You can test this PR using the following package version. |
Pinned, | ||
Unpinned | ||
} | ||
private PinnedStatus _isPinned; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why define this as an enum? The "Is" name prefix implies it is a bool. If you keep it as a bool you can avoid the converter entirely, correct?
get => _isPinned.ToString(); | ||
set | ||
{ | ||
try | ||
{ | ||
if (Enum.TryParse(value, out PinnedStatus pinState)) | ||
{ | ||
_isPinned = pinState; | ||
} | ||
} | ||
catch { } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is bad convention to be changing the data type in the property accessors. Whatever the underlying type is really should stay exposed as the property type.
@@ -9,6 +9,12 @@ internal class ClrPropertyViewModel : PropertyViewModel | |||
private Type _assignedType; | |||
private object? _value; | |||
private readonly Type _propertyType; | |||
private enum PinnedStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this enum can go away. Still, you shouldn't have two of the exact same enum defined.
@@ -11,6 +11,7 @@ internal abstract class PropertyViewModel : ViewModelBase | |||
public abstract string Name { get; } | |||
public abstract string Group { get; } | |||
public abstract Type AssignedType { get; } | |||
public abstract string IsPinned { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... three type? Bool in ConvertBack, String here and also the Enum?... should be just one as mentioned before. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, when it was only a bool passing it in as a groupdescription would have the groups titled true and false rather than pinned and unpinned.
The enum was just an attempt to avoid hardcoding the strings.
If there is another way to have the group descriptions renamed I will implement that but, I wasn't able to find anything. Even just hiding the name of the group would be a good option if possible.
It's a good start, but there are some problems to solve. The first and most annoying is the loss of the pinned properties when selecting a different control from treeview.
Instead of adding the internal class PinnedConverter : IValueConverter
{
public HashSet<string> PrinnedProperties { get; set; }
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var isPinned = false;
if (value is string propertyName)
{
isPinned = PrinnedProperties.Contains(propertyName);
}
return isPinned ? "Pinned" : "Unpinned";
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return BindingOperations.DoNothing;
}
} and use private PinnedConverter pinConverter = new();
...
pinConverter .PrinnedProperties = pinnedProperties
// view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.IsPinned)));
view.GroupDescriptions.Add(new DataGridPathGroupDescription(nameof(AvaloniaPropertyViewModel.PropertyName))
{
Converter = pinConverter ,
}
);
When a datagrid row is selected, you could add a AdornerDecorator that displays a button that allows you to pin/unpin the property . |
Those seem like great suggestions, I should have some time to get that done and another commit pushed this weekend. Thanks! |
@workgroupengineering I'm getting that wrapped up but, have never worked with adorners before and am having trouble getting that set up. Could you recommend any documentation or a tutorial to help me get that working? Or anywhere where something similar has been done in code would be a great help as well. Thanks! |
@lhsrebel72 I've seen it in Avalonia.Behaviors for example: https://github.com/AvaloniaUI/Avalonia.Xaml.Behaviors/tree/master/src/Avalonia.Xaml.Interactions.Draggable |
@timunie got ahead of me. |
What does the pull request do?
This has added a pinned variable to property view models and the functionality to use that to pin/unpin properties to the top of dev tools
What is the current behavior?
there is now a checkbox in dev tools that will allow you to pin properties to the top
What is the updated/expected behavior with this PR?
it works as intended other than one thing. It is currently using two headers: one for pinned and another for unpinned properties. I would like to only have one header but, I need to figure out how to bind the widths of each column in the separate data-grids together and have been unable to so far.
How was the solution implemented (if it's not obvious)?
I implemented a check box that is associated with an IsPinned variable on PropertyViewModel. ControlDetailsViewModel will then listen for it and add pinned properties to a separate data-grid above the original one.
Checklist
Added unit tests (if possible)?
Added XML documentation to any related classes?
Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentation
Breaking changes
Hopefully none, fingers crossed
Obsoletions / Deprecations
Fixed issues
Fixes #12242