forked from microsoft/WPF-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into implementing-heading-level
- Loading branch information
Showing
30 changed files
with
420 additions
and
155 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
# Lines starting with '#' are comments. | ||
# Each line is a file pattern followed by one or more owners. | ||
|
||
# These owners will be the default owners for everything in the repo, | ||
# and will automatically be added as reviewers to all pull requests. | ||
* @dotnet/wpf-developers |
This file contains 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 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 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 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 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 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
118 changes: 118 additions & 0 deletions
118
Sample Applications/CustomComboBox/ExpandableToggleButton.cs
This file contains 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,118 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
using System.Windows.Automation.Provider; | ||
using System.Windows.Controls; | ||
using System.Windows.Controls.Primitives; | ||
|
||
namespace CustomComboBox | ||
{ | ||
public class ExpandableToggleButton : Button | ||
{ | ||
private ExpandableToggleButtonAutomationPeer peer; | ||
|
||
private ExpandCollapseState state = ExpandCollapseState.Collapsed; | ||
|
||
public static readonly RoutedEvent ExpandedEvent = EventManager.RegisterRoutedEvent("Expanded", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExpandableToggleButton)); | ||
|
||
public static readonly RoutedEvent CollapsedEvent = EventManager.RegisterRoutedEvent("Collapsed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExpandableToggleButton)); | ||
|
||
public event RoutedEventHandler Expanded | ||
{ | ||
add { AddHandler(ExpandedEvent, value); } | ||
remove { RemoveHandler(ExpandedEvent, value); } | ||
} | ||
|
||
public event RoutedEventHandler Collapsed | ||
{ | ||
add { AddHandler(CollapsedEvent, value); } | ||
remove { RemoveHandler(CollapsedEvent, value); } | ||
} | ||
|
||
public ExpandCollapseState State | ||
{ | ||
get | ||
{ | ||
return this.state; | ||
} | ||
set | ||
{ | ||
ExpandCollapseState previousState = this.state; | ||
|
||
this.state = value; | ||
|
||
if ((this.peer != null) && this.state != previousState) | ||
{ | ||
this.peer.RaisePropertyChangedEvent( | ||
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, | ||
previousState, | ||
this.state); | ||
if(this.state == ExpandCollapseState.Collapsed) | ||
{ | ||
RoutedEventArgs collapsedEventArgs = new RoutedEventArgs(CollapsedEvent); | ||
RaiseEvent(collapsedEventArgs); | ||
} else | ||
{ | ||
RoutedEventArgs expandedEventArgs = new RoutedEventArgs(ExpandedEvent); | ||
RaiseEvent(expandedEventArgs); | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected override AutomationPeer OnCreateAutomationPeer() | ||
{ | ||
if(this.peer == null) | ||
{ | ||
this.peer = new ExpandableToggleButtonAutomationPeer(this); | ||
} | ||
|
||
return this.peer; | ||
} | ||
|
||
protected override void OnClick() | ||
{ | ||
this.State = (this.State == ExpandCollapseState.Collapsed ? ExpandCollapseState.Expanded : | ||
ExpandCollapseState.Collapsed); | ||
|
||
// base.OnClick(); | ||
} | ||
} | ||
|
||
public class ExpandableToggleButtonAutomationPeer : ButtonAutomationPeer, IExpandCollapseProvider | ||
{ | ||
private ExpandableToggleButton Button { get { return Owner as ExpandableToggleButton; } } | ||
|
||
public ExpandableToggleButtonAutomationPeer(ExpandableToggleButton owner) : base(owner) {} | ||
|
||
public override object GetPattern(PatternInterface patternInterface) | ||
{ | ||
if(patternInterface == PatternInterface.ExpandCollapse) | ||
{ | ||
return this; | ||
} | ||
return base.GetPattern(patternInterface); | ||
} | ||
|
||
public ExpandCollapseState ExpandCollapseState | ||
{ | ||
get | ||
{ | ||
return Button.State; | ||
} | ||
} | ||
|
||
public void Expand() | ||
{ | ||
Button.State = ExpandCollapseState.Expanded; | ||
} | ||
|
||
public void Collapse() | ||
{ | ||
Button.State = ExpandCollapseState.Collapsed; | ||
} | ||
} | ||
} |
This file contains 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 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.