Browse Source

CheckComboBox: dropdown closes when clicking outside the control.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
6b7823d4ac
  1. 18
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Implementation/CheckComboBox.cs
  2. 11
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Themes/Generic.xaml
  3. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/Selector.cs

18
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Implementation/CheckComboBox.cs

@ -17,7 +17,7 @@ namespace Microsoft.Windows.Controls
public CheckComboBox() public CheckComboBox()
{ {
Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
} }
#endregion //Constructors #endregion //Constructors
@ -66,6 +66,15 @@ namespace Microsoft.Windows.Controls
#endregion //Base Class Overrides #endregion //Base Class Overrides
#region Event Handlers
private void OnMouseDownOutsideCapturedElement(object sender, MouseButtonEventArgs e)
{
CloseDropDown();
}
#endregion //Event Handlers
#region Methods #region Methods
private void UpdateText() private void UpdateText()
@ -92,6 +101,13 @@ namespace Microsoft.Windows.Controls
return item; return item;
} }
private void CloseDropDown()
{
if (IsDropDownOpen)
IsDropDownOpen = false;
ReleaseMouseCapture();
}
#endregion //Methods #endregion //Methods
} }
} }

11
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CheckComboBox/Themes/Generic.xaml

@ -1,9 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Windows.Controls" xmlns:local="clr-namespace:Microsoft.Windows.Controls"
xmlns:coreConverters="clr-namespace:Microsoft.Windows.Controls.Core.Converters"
xmlns:chrome="clr-namespace:Microsoft.Windows.Controls.Chromes" xmlns:chrome="clr-namespace:Microsoft.Windows.Controls.Chromes"
xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives" > xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives" >
<coreConverters:InverseBoolConverter x:Key="InverseBoolConverter" />
<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/> <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
<Geometry x:Key="DownArrowGeometry">M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z</Geometry> <Geometry x:Key="DownArrowGeometry">M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z</Geometry>
@ -12,7 +15,6 @@
<Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/> <Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/> <Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}"> <ControlTemplate TargetType="{x:Type ToggleButton}">
@ -61,7 +63,7 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom"> <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" StaysOpen="False" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<Grid MinWidth="{Binding ActualWidth, ElementName=MainGrid}"> <Grid MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<ScrollViewer x:Name="DropDownScrollViewer"> <ScrollViewer x:Name="DropDownScrollViewer">
@ -78,7 +80,8 @@
<Border Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/> <Border Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
<TextBox Text="{TemplateBinding Text}" IsReadOnly="True" BorderThickness="0" Background="Transparent" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> <TextBox Text="{TemplateBinding Text}" IsReadOnly="True" BorderThickness="0" Background="Transparent" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<ToggleButton x:Name="PART_DropDownButton" Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}" /> <ToggleButton x:Name="PART_DropDownButton" Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"
IsHitTestVisible="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}"/>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/Selector.cs

@ -33,7 +33,7 @@ namespace Microsoft.Windows.Controls.Primitives
#region Properties #region Properties
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(CheckListBox), new PropertyMetadata((ICommand)null)); public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(Selector), new PropertyMetadata((ICommand)null));
[TypeConverter(typeof(CommandConverter))] [TypeConverter(typeof(CommandConverter))]
public ICommand Command public ICommand Command
{ {

Loading…
Cancel
Save