-
-
Notifications
You must be signed in to change notification settings - Fork 983
Fix ListView to be compatible when ListView.View is a GridView #979
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
Merged
pomianowski
merged 9 commits into
lepoco:development
from
koal44:fix/gridview-compatibility
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f055c4c
Fix ListView to be compatible when ListView.View is a GridView
koal44 12fc801
Merge remote-tracking branch 'upstream/development' into fix/gridview…
koal44 0271f7a
Change ViewState's type from a string to an enum of two states: Defau…
koal44 96d10c0
Implement the GridView feature by binding directly to the View property.
koal44 7cbdc7a
Merge branch 'development' into fix/gridview-compatibility
pomianowski c621d71
Merge branch 'development' into fix/gridview-compatibility
koal44 91576f1
Merge branch 'fix/gridview-compatibility' of https://github.com/koal4…
koal44 9c2391a
Re-implement custom ui:ListView class and remove the ListViewViewStat…
koal44 16c9d10
Addd documentation and tool to the VS tools manifest
koal44 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
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,88 @@ | ||
| namespace Wpf.Ui.Controls; | ||
|
|
||
| /// <summary> | ||
| /// Extends <see cref="System.Windows.Controls.ListView"/>, and adds customized support <see cref="ListViewViewState.GridView"/> or <see cref="ListViewViewState.Default"/>. | ||
| /// </summary> | ||
| /// <example> | ||
| /// <code lang="xml"> | ||
| /// <ui:ListView ItemsSource="{Binding ...}" > | ||
| /// <ui:ListView.View> | ||
| /// <GridView> | ||
| /// <GridViewColumn | ||
| /// DisplayMemberBinding="{Binding FirstName}" | ||
| /// Header="First Name" /> | ||
| /// <GridViewColumn | ||
| /// DisplayMemberBinding="{Binding LastName}" | ||
| /// Header="Last Name" /> | ||
| /// </GridView> | ||
| /// </ui:ListView.View> | ||
| /// </ui:ListView> | ||
| /// </code> | ||
| /// </example> | ||
| public class ListView : System.Windows.Controls.ListView | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| /// <summary>Identifies the <see cref="ViewState"/> dependency property.</summary> | ||
| public static readonly DependencyProperty ViewStateProperty = DependencyProperty.Register(nameof(ViewState), typeof(ListViewViewState), typeof(ListView), new FrameworkPropertyMetadata(ListViewViewState.Default, OnViewStateChanged)); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the view state of the <see cref="ListView"/>, enabling custom logic based on the current view. | ||
| /// </summary> | ||
| /// <value>The current view state of the <see cref="ListView"/>.</value> | ||
| public ListViewViewState ViewState | ||
| { | ||
| get => (ListViewViewState)GetValue(ViewStateProperty); | ||
| set => SetValue(ViewStateProperty, value); | ||
| } | ||
|
|
||
| private static void OnViewStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
| { | ||
| if (d is not ListView self) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| self.OnViewStateChanged(e); | ||
| } | ||
|
|
||
| protected virtual void OnViewStateChanged(DependencyPropertyChangedEventArgs e) | ||
| { | ||
| // Hook for derived classes to react to ViewState property changes | ||
| } | ||
|
|
||
| public ListView() | ||
| { | ||
| Loaded += OnLoaded; | ||
| } | ||
|
|
||
| private void OnLoaded(object sender, RoutedEventArgs e) | ||
| { | ||
| Loaded -= OnLoaded; // prevent memory leaks | ||
|
|
||
| // Setup initial ViewState and hook into View property changes | ||
| var descriptor = DependencyPropertyDescriptor.FromProperty(System.Windows.Controls.ListView.ViewProperty, typeof(System.Windows.Controls.ListView)); | ||
| descriptor?.AddValueChanged(this, OnViewPropertyChanged); | ||
| UpdateViewState(); // set the initial state | ||
| } | ||
|
|
||
| private void OnViewPropertyChanged(object? sender, EventArgs e) | ||
| { | ||
| UpdateViewState(); | ||
| } | ||
|
|
||
| private void UpdateViewState() | ||
| { | ||
| ListViewViewState viewState = View switch | ||
| { | ||
| System.Windows.Controls.GridView => ListViewViewState.GridView, | ||
| null => ListViewViewState.Default, | ||
| _ => ListViewViewState.Default | ||
| }; | ||
|
|
||
| SetCurrentValue(ViewStateProperty, viewState); | ||
| } | ||
|
|
||
| static ListView() | ||
| { | ||
| DefaultStyleKeyProperty.OverrideMetadata(typeof(ListView), new FrameworkPropertyMetadata(typeof(ListView))); | ||
| } | ||
| } | ||
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.