WPF ComboBox样式

config_man 2015-06-01 03:10:00
效果:http://blog.csdn.net/config_man/article/details/45643451
目前只能点击三角区域按钮进行下拉选择。

想实现以下功能:
1:操作键盘时,当按Tab键到会员等级那个ComboBox时,下拉显示子项。上下键进行选择,选择后下拉就不显示了。
2:鼠标单击会员等级ComboBox的TextBox区域时,下拉显示子项。

附带Demo代码(可直接新建工程时,整个替换xaml):

<Window x:Class="ComboBoxStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
<Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
</ControlTemplate>
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="2" BorderBrush="#e8e8e8" />

<Border Grid.Column="1" Background="#e8e8e8" Cursor="Hand"/>
<Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z" Margin="16,16,10,10" Stretch="Fill" Fill="White" />
</Grid>
</ControlTemplate>

<Style TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border x:Name="bd" >
<Grid>
<!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
<ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
<ContentPresenter HorizontalAlignment="Left" Margin="11,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>

<!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
<TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>

<!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
<Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
<Border x:Name="DropDownBorder" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/>
<ScrollViewer Margin="4,6,4,6" Style="{DynamicResource SimpleScrollViewer}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
</ScrollViewer>
</Grid>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" TargetName="bd" Value="#7eb5eb" />
<Setter Property="BorderThickness" TargetName="bd" Value="2" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ComboBox Width="303" BorderBrush="#e8e8e8" VerticalContentAlignment="Center" Margin="60,78,154,201" ItemsSource="{Binding ElementName=listbox}">
<ComboBoxItem>aaa</ComboBoxItem>
<ComboBoxItem>bbb</ComboBoxItem>
<ComboBoxItem>ccc</ComboBoxItem>
<ComboBoxItem>ddd</ComboBoxItem>
</ComboBox>
<Button Content="Button" HorizontalAlignment="Left" Margin="166,209,0,0" VerticalAlignment="Top" Width="87" Click="Button_Click" Height="30"/>
</Grid>
</Window>


有劳了。
...全文
811 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
config_man 2015-06-12
  • 打赏
  • 举报
回复
引用 15 楼 u013687415 的回复:
这样啊,我没试过keydown,以为差不多的
谢谢哈,我结贴啦~~
config_man 2015-06-11
  • 打赏
  • 举报
回复
不知道你的用了我的样式了吗?我这个需要在样式的基础上增加这个tab功能的
config_man 2015-06-11
  • 打赏
  • 举报
回复
引用 10 楼 u013687415 的回复:
那是电脑问题么,汗 你看看这个tab一下能不能下拉 http://download.csdn.net/detail/u013687415/8791951
恩,这个是可以的。
O_OQAQ 2015-06-11
  • 打赏
  • 举报
回复
引用 14 楼 config_man 的回复:
[quote=引用 13 楼 u013687415 的回复:] [quote=引用 12 楼 config_man 的回复:] 不知道你的用了我的样式了吗?我这个需要在样式的基础上增加这个tab功能的
我是复制你在这个贴发的那段 只有名字不同,然后增加了Window_PreviewKeyUp

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" PreviewKeyUp="Window_PreviewKeyUp">
    <Window.Resources>
        <ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
            <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
        </ControlTemplate>
        <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" BorderThickness="2" BorderBrush="#e8e8e8" />

                <Border Grid.Column="1" Background="#e8e8e8" Cursor="Hand"/>
                <Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z" Margin="16,16,10,10" Stretch="Fill" Fill="White" />
            </Grid>
        </ControlTemplate>

        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Border x:Name="bd" >
                            <Grid>
                                <!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
                                <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
                                <ContentPresenter HorizontalAlignment="Left" Margin="11,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>

                                <!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
                                <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>

                                <!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
                                <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
                                    <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
                                        <Border x:Name="DropDownBorder" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/>
                                        <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource SimpleScrollViewer}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
                                            <!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
                                        </ScrollViewer>
                                    </Grid>
                                </Popup>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter Property="BorderBrush" TargetName="bd" Value="#7eb5eb" />
                                <Setter Property="BorderThickness" TargetName="bd" Value="2" />
                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ComboBox  Name="ComboBox1" Width="303" BorderBrush="#e8e8e8" VerticalContentAlignment="Center" Margin="60,78,154,201" ItemsSource="{Binding ElementName=listbox}">
            <ComboBoxItem>aaa</ComboBoxItem>
            <ComboBoxItem>bbb</ComboBoxItem>
            <ComboBoxItem>ccc</ComboBoxItem>
            <ComboBoxItem>ddd</ComboBoxItem>
        </ComboBox>
        <Button Content="Button" HorizontalAlignment="Left" Margin="166,209,0,0" VerticalAlignment="Top" Width="87" Click="Button_Click" Height="30"/>
    </Grid>
</Window>
[/quote] 这段可行。 我刚才比较了两个文件的区别,发现原因是因为事件:PreviewKeyDown事件没效果,而PreviewKeyUp事件才是有效果的。[/quote] 这样啊,我没试过keydown,以为差不多的
config_man 2015-06-11
  • 打赏
  • 举报
回复
引用 13 楼 u013687415 的回复:
[quote=引用 12 楼 config_man 的回复:] 不知道你的用了我的样式了吗?我这个需要在样式的基础上增加这个tab功能的
我是复制你在这个贴发的那段 只有名字不同,然后增加了Window_PreviewKeyUp

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" PreviewKeyUp="Window_PreviewKeyUp">
    <Window.Resources>
        <ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
            <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
        </ControlTemplate>
        <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" BorderThickness="2" BorderBrush="#e8e8e8" />

                <Border Grid.Column="1" Background="#e8e8e8" Cursor="Hand"/>
                <Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z" Margin="16,16,10,10" Stretch="Fill" Fill="White" />
            </Grid>
        </ControlTemplate>

        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Border x:Name="bd" >
                            <Grid>
                                <!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
                                <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
                                <ContentPresenter HorizontalAlignment="Left" Margin="11,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>

                                <!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
                                <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>

                                <!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
                                <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
                                    <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
                                        <Border x:Name="DropDownBorder" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/>
                                        <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource SimpleScrollViewer}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
                                            <!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
                                        </ScrollViewer>
                                    </Grid>
                                </Popup>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter Property="BorderBrush" TargetName="bd" Value="#7eb5eb" />
                                <Setter Property="BorderThickness" TargetName="bd" Value="2" />
                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ComboBox  Name="ComboBox1" Width="303" BorderBrush="#e8e8e8" VerticalContentAlignment="Center" Margin="60,78,154,201" ItemsSource="{Binding ElementName=listbox}">
            <ComboBoxItem>aaa</ComboBoxItem>
            <ComboBoxItem>bbb</ComboBoxItem>
            <ComboBoxItem>ccc</ComboBoxItem>
            <ComboBoxItem>ddd</ComboBoxItem>
        </ComboBox>
        <Button Content="Button" HorizontalAlignment="Left" Margin="166,209,0,0" VerticalAlignment="Top" Width="87" Click="Button_Click" Height="30"/>
    </Grid>
</Window>
[/quote] 这段可行。 我刚才比较了两个文件的区别,发现原因是因为事件:PreviewKeyDown事件没效果,而PreviewKeyUp事件才是有效果的。
O_OQAQ 2015-06-11
  • 打赏
  • 举报
回复
引用 12 楼 config_man 的回复:
不知道你的用了我的样式了吗?我这个需要在样式的基础上增加这个tab功能的
我是复制你在这个贴发的那段 只有名字不同,然后增加了Window_PreviewKeyUp

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" PreviewKeyUp="Window_PreviewKeyUp">
    <Window.Resources>
        <ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
            <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
        </ControlTemplate>
        <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" BorderThickness="2" BorderBrush="#e8e8e8" />

                <Border Grid.Column="1" Background="#e8e8e8" Cursor="Hand"/>
                <Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z" Margin="16,16,10,10" Stretch="Fill" Fill="White" />
            </Grid>
        </ControlTemplate>

        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Border x:Name="bd" >
                            <Grid>
                                <!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
                                <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
                                <ContentPresenter HorizontalAlignment="Left" Margin="11,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>

                                <!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
                                <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>

                                <!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
                                <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
                                    <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
                                        <Border x:Name="DropDownBorder" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/>
                                        <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource SimpleScrollViewer}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
                                            <!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
                                        </ScrollViewer>
                                    </Grid>
                                </Popup>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter Property="BorderBrush" TargetName="bd" Value="#7eb5eb" />
                                <Setter Property="BorderThickness" TargetName="bd" Value="2" />
                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ComboBox  Name="ComboBox1" Width="303" BorderBrush="#e8e8e8" VerticalContentAlignment="Center" Margin="60,78,154,201" ItemsSource="{Binding ElementName=listbox}">
            <ComboBoxItem>aaa</ComboBoxItem>
            <ComboBoxItem>bbb</ComboBoxItem>
            <ComboBoxItem>ccc</ComboBoxItem>
            <ComboBoxItem>ddd</ComboBoxItem>
        </ComboBox>
        <Button Content="Button" HorizontalAlignment="Left" Margin="166,209,0,0" VerticalAlignment="Top" Width="87" Click="Button_Click" Height="30"/>
    </Grid>
</Window>
O_OQAQ 2015-06-10
  • 打赏
  • 举报
回复
引用 7 楼 u013687415 的回复:
[quote=引用 6 楼 config_man 的回复:] [quote=引用 5 楼 u013687415 的回复:] 主窗体增加Previewkeyup或Previewkeydown private void Window_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Tab && ComboBox1.IsFocused) { ComboBox1.IsDropDownOpen = true; } }
没有效果。只是ComboBox获得了焦点,其它没任何变化。[/quote] 额,我电脑上是可以的[/quote] 对了,iseditable不要选,选了就不行了
O_OQAQ 2015-06-10
  • 打赏
  • 举报
回复
引用 6 楼 config_man 的回复:
[quote=引用 5 楼 u013687415 的回复:] 主窗体增加Previewkeyup或Previewkeydown private void Window_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Tab && ComboBox1.IsFocused) { ComboBox1.IsDropDownOpen = true; } }
没有效果。只是ComboBox获得了焦点,其它没任何变化。[/quote] 额,我电脑上是可以的
config_man 2015-06-10
  • 打赏
  • 举报
回复
引用 5 楼 u013687415 的回复:
主窗体增加Previewkeyup或Previewkeydown private void Window_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Tab && ComboBox1.IsFocused) { ComboBox1.IsDropDownOpen = true; } }
没有效果。只是ComboBox获得了焦点,其它没任何变化。
O_OQAQ 2015-06-10
  • 打赏
  • 举报
回复
那是电脑问题么,汗 你看看这个tab一下能不能下拉 http://download.csdn.net/detail/u013687415/8791951
config_man 2015-06-10
  • 打赏
  • 举报
回复
引用 8 楼 u013687415 的回复:
[quote=引用 7 楼 u013687415 的回复:] [quote=引用 6 楼 config_man 的回复:] [quote=引用 5 楼 u013687415 的回复:] 主窗体增加Previewkeyup或Previewkeydown private void Window_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Tab && ComboBox1.IsFocused) { ComboBox1.IsDropDownOpen = true; } }
没有效果。只是ComboBox获得了焦点,其它没任何变化。[/quote] 额,我电脑上是可以的[/quote] 对了,iseditable不要选,选了就不行了[/quote] 我的源码里没有iseditable呀。
O_OQAQ 2015-06-09
  • 打赏
  • 举报
回复
主窗体增加Previewkeyup或Previewkeydown private void Window_PreviewKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Tab && ComboBox1.IsFocused) { ComboBox1.IsDropDownOpen = true; } }
config_man 2015-06-01
  • 打赏
  • 举报
回复
引用 3 楼 duanzi_peng 的回复:
[quote=引用 2 楼 config_man 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 这是个什么提问??
请问我哪里说的让您不太明白吗。 提问主要是关于会员等级的下拉框功能,目前只能点击ComboBox三角区域进行下拉选择。 想实现以下功能: 1:操作键盘时,当按Tab键到会员等级那个ComboBox时,下拉显示子项。上下键进行选择,选择后下拉就不显示了。 2:鼠标单击会员等级ComboBox的TextBox区域时,下拉显示子项。[/quote] 1:你可以 在模板里写触发器,Tab键到,其实就是获取焦点 isFocused 为true,让面板 Popup 显示。至于上下键选择 ,这个好像item会自动触发的。 2:这个好像好 获取焦点 是一个道理的。[/quote] 关于1:我试过IsFocused为true,让Popup显示,但在上下键选择时,有问题。具体为:上下键只按一次,Popup就不显示了。不能连续向下或向上进行选择。 关于2:这个试过各种方法,没搞出来(主要对样式不太了解,一直做功能性开发,现在正学习样式,但目前还没水平解决)。所以才发帖求助。
exception92 2015-06-01
  • 打赏
  • 举报
回复
引用 2 楼 config_man 的回复:
[quote=引用 1 楼 duanzi_peng 的回复:] 这是个什么提问??
请问我哪里说的让您不太明白吗。 提问主要是关于会员等级的下拉框功能,目前只能点击ComboBox三角区域进行下拉选择。 想实现以下功能: 1:操作键盘时,当按Tab键到会员等级那个ComboBox时,下拉显示子项。上下键进行选择,选择后下拉就不显示了。 2:鼠标单击会员等级ComboBox的TextBox区域时,下拉显示子项。[/quote] 1:你可以 在模板里写触发器,Tab键到,其实就是获取焦点 isFocused 为true,让面板 Popup 显示。至于上下键选择 ,这个好像item会自动触发的。 2:这个好像好 获取焦点 是一个道理的。
config_man 2015-06-01
  • 打赏
  • 举报
回复
引用 1 楼 duanzi_peng 的回复:
这是个什么提问??
请问我哪里说的让您不太明白吗。 提问主要是关于会员等级的下拉框功能,目前只能点击ComboBox三角区域进行下拉选择。 想实现以下功能: 1:操作键盘时,当按Tab键到会员等级那个ComboBox时,下拉显示子项。上下键进行选择,选择后下拉就不显示了。 2:鼠标单击会员等级ComboBox的TextBox区域时,下拉显示子项。
exception92 2015-06-01
  • 打赏
  • 举报
回复
这是个什么提问??

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧