- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我为 ComboBox
添加了以下样式,这是我一年前偶然发现的 WPFToolkit 的一部分。
它缺少一项基本功能,即,如果我在 ComboBox
的 TextBox
内单击,我希望下拉菜单照常展开。在此模板中,只能通过直接单击 ComboBoxToggleButton
打开下拉菜单。
我不知道在模板样式中寻找什么,你能以某种方式指导我吗?
模板样式:
<ControlTemplate x:Key="ComboBoxToggleButton"
TargetType="{x:Type ToggleButton}">
<ControlTemplate.Resources>
<Storyboard x:Key="HoverOn">
<DoubleAnimation Duration="00:00:00.1000000"
Storyboard.TargetName="rectangleOver"
Storyboard.TargetProperty="Opacity"
To="0.8" />
<ColorAnimation Duration="00:00:00.1000000"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
To="#FFFFFFFF" />
</Storyboard>
<Storyboard x:Key="HoverOff">
<DoubleAnimation Duration="00:00:00.4000000"
Storyboard.TargetName="rectangleOver"
Storyboard.TargetProperty="Opacity"
To="0" />
<ColorAnimation Duration="00:00:00.4000000"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
To="#FFffffff" />
</Storyboard>
<Storyboard x:Key="PressedOn">
<DoubleAnimation Duration="00:00:00.1000000"
Storyboard.TargetName="rectanglePress"
Storyboard.TargetProperty="Opacity"
To="0.8" />
<ColorAnimation Duration="00:00:00.1000000"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
To="#FFFFFFFF" />
</Storyboard>
<Storyboard x:Key="PressedOff">
<DoubleAnimation Duration="00:00:00.4000000"
Storyboard.TargetName="rectanglePress"
Storyboard.TargetProperty="Opacity"
To="0" />
<ColorAnimation Duration="00:00:00.4000000"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
To="#FFffffff" />
</Storyboard>
<Storyboard x:Key="CheckedOn">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="BackgroundChecked"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.1000000"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="CheckedOff">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="BackgroundChecked"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000"
Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid x:Name="grid">
<Rectangle x:Name="Background"
Fill="#ffffff"
Stroke="#ffc6c6c6"
RadiusX="3"
RadiusY="3"
IsHitTestVisible="false" />
<Rectangle x:Name="BackgroundChecked"
Margin="1"
IsHitTestVisible="false"
Opacity="0">
<Rectangle.Fill>
<SolidColorBrush Color="{DynamicResource WhiteColor}" />
</Rectangle.Fill>
</Rectangle>
<Rectangle x:Name="rectangleOver"
Width="15"
Stroke="#FFE8E8E8"
HorizontalAlignment="Right"
Opacity="0"
Fill="{DynamicResource MouseOverBrush}" />
<Rectangle x:Name="rectanglePress"
Width="15"
Stroke="#FC9E9D9B"
HorizontalAlignment="Right"
Opacity="0"
Fill="{DynamicResource PressedBrush}" />
<Rectangle x:Name="DisabledVisualElement"
Margin="1"
Fill="{DynamicResource DisabledBackgroundBrush}"
IsHitTestVisible="false"
Visibility="Collapsed" />
<Path x:Name="BtnArrow"
Margin="0,0,4,0"
Width="6"
Fill="{DynamicResource GlyphBrush}"
Stretch="Uniform"
HorizontalAlignment="Right"
Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z " />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed"
Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource PressedOff}"
x:Name="PressedOff_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressedOn}"
x:Name="PressedOn_BeginStoryboard" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsMouseOver"
Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource HoverOff}"
x:Name="HoverOff_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource HoverOn}" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsChecked"
Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CheckedOff}"
x:Name="CheckedOff_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource CheckedOn}"
x:Name="CheckedOn_BeginStoryboard" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Foreground"
Value="{DynamicResource DisabledForegroundBrush}" />
<Setter Property="Visibility"
TargetName="DisabledVisualElement"
Value="Visible" />
<Setter Property="Fill"
TargetName="Background"
Value="{DynamicResource DisabledBackgroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ComboBoxTextBox"
TargetType="{x:Type TextBox}">
<Border x:Name="PART_ContentHost"
Focusable="False"
Background="{TemplateBinding Background}" />
</ControlTemplate>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels"
Value="true" />
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="FontSize"
Value="13" />
<Setter Property="FontWeight"
Value="Bold" />
<Setter Property="Padding"
Value="6,2,25,2" />
<Setter Property="Margin"
Value="3" />
<Setter Property="ToolTipService.ShowOnDisabled"
Value="True" />
<Setter Property="Template"
Value="{DynamicResource ComboBoxTemplate}" />
<Setter Property="Validation.ErrorTemplate"
Value="{StaticResource SablonaChybovehoHlaseni}" />
</Style>
<ControlTemplate x:Key="ComboBoxTemplate"
TargetType="{x:Type ComboBox}">
<ControlTemplate.Resources>
<Storyboard x:Key="FocusedOn">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="FocusVisualElement"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.1000000"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="FocusedOff">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="FocusVisualElement"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000"
Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<ToggleButton Grid.Column="2"
Template="{DynamicResource ComboBoxToggleButton}"
x:Name="ToggleButton"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
ClickMode="Press" />
<ContentPresenter HorizontalAlignment="Stretch"
Margin="3,3,23,3"
x:Name="ContentSite"
VerticalAlignment="Top"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="True">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
TextWrapping="Wrap" />
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
<!--Textbox for ComboBox-->
<!--Set transparent background of TextBox-->
<TextBox Visibility="Hidden"
Template="{DynamicResource ComboBoxTextBox}"
HorizontalAlignment="Stretch"
Margin="3,3,23,3"
x:Name="PART_EditableTextBox"
Style="{x:Null}"
VerticalAlignment="Top"
Focusable="True"
Background="Transparent"
TextWrapping="Wrap"
IsReadOnly="{TemplateBinding IsReadOnly}" />
<Rectangle x:Name="DisabledVisualElement"
Fill="{DynamicResource DisabledBackgroundBrush}"
Stroke="{DynamicResource DisabledBorderBrush}"
RadiusX="3"
RadiusY="3"
IsHitTestVisible="false"
Opacity="0" />
<Rectangle x:Name="FocusVisualElement"
Margin="-1"
RadiusX="3"
RadiusY="3"
Stroke="{DynamicResource FocusBrush}"
StrokeThickness="1"
IsHitTestVisible="false"
Opacity="0" />
<Popup IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
x:Name="Popup"
Focusable="False"
AllowsTransparency="True"
PopupAnimation="Slide"
Margin="0,1,0,0">
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{TemplateBinding ActualWidth}"
x:Name="DropDown"
SnapsToDevicePixels="True">
<Border x:Name="DropDownBorder"
Margin="0,-1,0,0"
BorderBrush="{DynamicResource ControlBorderBrush}"
BorderThickness="1"
CornerRadius="0,0,3,3"
Background="{DynamicResource WhiteColorBrush}">
<!--ControlBackgroundBrush-->
<ScrollViewer Margin="4,6,4,6"
SnapsToDevicePixels="True"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
CanContentScroll="True">
<StackPanel IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Border>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused"
Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource FocusedOff}"
x:Name="FocusedOff_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource FocusedOn}" />
</Trigger.EnterActions>
<Setter Property="CornerRadius"
TargetName="DropDownBorder"
Value="3" />
</Trigger>
<Trigger Property="HasItems"
Value="false">
<Setter Property="MinHeight"
Value="95"
TargetName="DropDownBorder" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="{DynamicResource DisabledForegroundBrush}" />
<Setter Property="Opacity"
TargetName="DisabledVisualElement"
Value="1" />
</Trigger>
<Trigger Property="IsGrouping"
Value="true">
<Setter Property="ScrollViewer.CanContentScroll"
Value="false" />
</Trigger>
<Trigger Property="AllowsTransparency"
SourceName="Popup"
Value="true">
<Setter Property="CornerRadius"
Value="4"
TargetName="DropDownBorder" />
<Setter Property="Margin"
Value="0,2,0,0"
TargetName="DropDownBorder" />
</Trigger>
<Trigger Property="IsEditable"
Value="true">
<Setter Property="IsTabStop"
Value="false" />
<Setter Property="Visibility"
Value="Visible"
TargetName="PART_EditableTextBox" />
<Setter Property="Visibility"
Value="Hidden"
TargetName="ContentSite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
最佳答案
ComboBox 有两种用例。第一个是 IsEditable 为 false 时。在这种情况下,用户只能选择预定义的项目。第二种是当 IsEditable 为 true 时,这种情况允许用户输入文本以及选择预定义的项目。
使用默认的 Aero 样式,单击“文本”区域(即当 IsEditable 为 true 时)不会弹出下拉菜单。单击焦点/选择文本。其他样式将打开下拉菜单。
为了实现此目的,在另一个控件的顶部放置了一个透明的 ToggleButton,用于切换下拉列表的可见性。像这样的东西:
<Grid Grid.IsSharedSizeScope="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"
SharedSizeGroup="ComboBoxButton"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="PART_EditableTextBox"
Grid.Column="1"
Style="{StaticResource ComboBoxEditableTextBox}"
IsReadOnly="{Binding Path=IsReadOnly,RelativeSource={RelativeSource TemplatedParent}}"
Margin="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<ToggleButton Background="{x:Null}"
Grid.ColumnSpan="3"
Style="{StaticResource ComboBoxTransparentButtonStyle}"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"/>
</Grid>
关于WPF ComboBox 具有自定义样式,单击 ComboBox 内部后无法展开 DropDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6520973/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我有一个包含一些数据的网格(用户列表)。对于每一行,我有许多操作,例如更新、删除、激活、暂停、查看您命名的订单。 而不是放置如此多的按钮,这些按钮将填充超过 400-500像素 我想放置一个组合框,其
在我的一个对话框中,我有以下控制: 我在其他地方填充 ComboBox,如下所示: 但是,如果我没有创建 ComboBox 位,MSI 仍将构
我在项目中为 MVC 使用了 kendo complete。 我有某些形式的国家/地区列表,我显示国家/地区名称,但存储国家/地区代码。 我有以下问题:当用户输入不在列表中的内容时,该值将发送到服务器
我有一个组合框,其中的值是从托管 bean 填充的,如下所示: keywordlist.setConnDB("jdbc:sqlserver://xx.xx.x.xx:1433;DatabaseName
我有一个 ComboBox,它绑定(bind)到 ViewModel 中的复杂类型集合,这些类型的长度可以是任意数量,具体取决于用户的偏好。 我已经创建了一个基于 ComboBox 默认值的样式,并且
我做了一个转换器: public class BooleanToDateConverter implements Converter { private static final long s
编辑:由于 Rob 的回答,我已经更新了下面的代码,现在它可以工作了。 我找到了几页显示如何执行此操作的页面( http://www.cmcrossroads.com/content/view/131
我是 PyQT 的新手。 我有兴趣向 tableView 的每一行添加一个组合框。在 PyQT 4 中可能吗? 我知道,在 QT5 中是可能的,但不确定 PyQT。 预先感谢您的帮助。 最佳答案 如果
我对 JavaFX(8)、HBox、ComboBox 和 HGrow 有问题。 HGrow 不能与 ComboBox 结合使用。 (信息:使用 TextField (而不是 ComboBox),它按预
我有一个 XAML UserControl连接到 ImportPresenter View 模型。有四个ComboBox我的 XAML 中的项目: CashActivityTypeBAI CashAc
我将两个组合框绑定(bind)到同一个 listviewcollection。问题是在一个组合框中选择一个值会导致另一个组合框选定项更改为第一个组合框的确切值。它们是耦合的,我希望它们彼此独立。 My
我正在尝试在 extjs 3.4 中的组合框中的选项之间添加一行。我可以添加该行,但不能用我的远程位置的数据填充它。 (如果我删除修改的 tpl 选项,它就会填充)。 这是我的代码。我只需要在“组”字
我被 WIX 安装程序中的组合框和自定义操作困住了。 我有一个包含几个值的组合框(下拉菜单)。当用户从此下拉列表中选择一个值时,我想在屏幕上显示一些文本(对于下拉列表中的每个项目都是唯一的)。 在 .
我有 ComboBox cbx 和一个包含选项卡的 TabPane(选项卡:t)和一个按钮 b1。因此,单击此按钮 b1 时,它会在 TabPane 中添加一个新选项卡 t,并在包含以下内容的 Com
我有两个组合框:水果和饮料。 fruits 具有字符串:“apple”、“orange”、“banana” drinks 具有字符串:“water”、“coffee”、“juice” 如何制作一个新组
我必须监听什么事件,以便在用户从(可编辑的)WPF ComboBox control 中选择一个选项时得到通知? 我是否必须先访问 Items 属性才能收听 Items.CurrentChanged?
我有以下简单的 QML 组合框: import QtQuick 2.0 import QtQuick.Controls 1.4 import si.mikroelektronika 1.0 Item
当我创建组合框时,列表中没有项目。现在,当我单击下拉按钮时,会调用一个函数(通过 postcommand 选项),但是一旦在我的函数中,我不知道如何在组合框的列表框中设置值。 代码如下: #u
我有两个组合框 我使用 LINQ-to-Entities 来填充 cmbGroup 组合框 Dim db as myDataEntity cmbGroup.ItemsSource = db.Mak
我是一名优秀的程序员,十分优秀!