Browse Source

trying to get SplitButton to behave properly, not having much success.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
2021b454fc
  1. 67
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/SplitButton/SplitButton.cs
  2. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

67
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/SplitButton/SplitButton.cs

@ -1,17 +1,9 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Diagnostics;
namespace Microsoft.Windows.Controls namespace Microsoft.Windows.Controls
{ {
@ -19,7 +11,7 @@ namespace Microsoft.Windows.Controls
{ {
#region Members #region Members
ToggleButton _dropDownButton; ToggleButton _toggleButton;
Popup _popup; Popup _popup;
#endregion //Members #endregion //Members
@ -31,6 +23,12 @@ namespace Microsoft.Windows.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(SplitButton), new FrameworkPropertyMetadata(typeof(SplitButton))); DefaultStyleKeyProperty.OverrideMetadata(typeof(SplitButton), new FrameworkPropertyMetadata(typeof(SplitButton)));
} }
public SplitButton()
{
Keyboard.AddKeyDownHandler(this, OnKeyDown);
Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
}
#endregion //Constructors #endregion //Constructors
#region Properties #region Properties
@ -77,6 +75,7 @@ namespace Microsoft.Windows.Controls
protected virtual void OnIsOpenChanged(bool oldValue, bool newValue) protected virtual void OnIsOpenChanged(bool oldValue, bool newValue)
{ {
// TODO: Add your property changed side-effects. Descendants can override as well. // TODO: Add your property changed side-effects. Descendants can override as well.
Debug.WriteLine("{0} : {1}", oldValue, newValue);
} }
#endregion //IsOpen #endregion //IsOpen
@ -89,11 +88,57 @@ namespace Microsoft.Windows.Controls
{ {
base.OnApplyTemplate(); base.OnApplyTemplate();
_dropDownButton = (ToggleButton)GetTemplateChild("PART_ToggleButton"); _toggleButton = (ToggleButton)GetTemplateChild("PART_ToggleButton");
_toggleButton.Click += new RoutedEventHandler(_toggleButton_Click);
_popup = (Popup)GetTemplateChild("PART_Popup"); _popup = (Popup)GetTemplateChild("PART_Popup");
_popup.Opened += Popup_Opened;
}
void _toggleButton_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("IsOpen : {0} | IsChecked : {1}", IsOpen, _toggleButton.IsChecked);
} }
#endregion //Base Class Overrides #endregion //Base Class Overrides
#region Event Handlers
void Popup_Opened(object sender, EventArgs e)
{
Mouse.Capture(this, CaptureMode.SubTree);
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape:
case Key.Tab:
{
CloseDropDown();
break;
}
}
}
private void OnMouseDownOutsideCapturedElement(object sender, MouseButtonEventArgs e)
{
CloseDropDown();
}
#endregion //Event Handlers
#region Methods
private void CloseDropDown()
{
if (IsOpen)
IsOpen = false;
ReleaseMouseCapture();
}
#endregion //Methods
} }
} }

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -1238,7 +1238,7 @@
StaysOpen="False" StaysOpen="False"
Placement="Bottom" Placement="Bottom"
Focusable="False" Focusable="False"
IsOpen="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"> IsOpen="{Binding IsChecked, ElementName=PART_ToggleButton}">
<!-- TODO: Create Popup Styles that can be reused on all popups in the toolkit--> <!-- TODO: Create Popup Styles that can be reused on all popups in the toolkit-->
<Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" > <Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" >
<ContentPresenter Content="{TemplateBinding DropDownContent}" /> <ContentPresenter Content="{TemplateBinding DropDownContent}" />
@ -1246,6 +1246,9 @@
</Popup> </Popup>
</Grid> </Grid>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>

Loading…
Cancel
Save