2

我一直在查看以下有关如何设置样式的示例ComboBox,但是在进入可编辑组合框时我无法创建焦点效果。每当ComboBox接收到焦点时,它应该进入编辑模式并且组件应该具有焦点样式。

基本问题是,每当我进入编辑模式时,ComboBox实际上焦点不是周围,而是文本子组件,我无法在Trigger文本组件上创建一个修改ComboBox边框样式的文本组件,因为我不知道如何从触发器中引用父组件。

我尝试添加ControlTemplate Trigger,TextBox或样式触发器。我试图ComboBox通过名称或使用TemplateBinding选项来引用,但没有任何运气。一个简单的例子将不胜感激。

4

3 回答 3

4

将 IsKeyboardFocusWithin 绑定到 IsDropDownOpen

<ComboBox ItemsSource="{Binding SortedItems}"
          StaysOpenOnEdit="True"
          IsDropDownOpen="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
于 2010-02-18T20:27:21.247 回答
1
  private void cmbSpecialHandling_GotFocus(object sender, RoutedEventArgs e)
        {
            Thickness th = new Thickness(2);
            cmbSpecialHandling.BorderThickness = th;
            cmbSpecialHandling.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush;
        }

        private void cmbSpecialHandling_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            Thickness th = new Thickness(2);
            cmbSpecialHandling.BorderThickness = th;
            cmbSpecialHandling.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush;
        }

        private void cmbSpecialHandling_LostFocus(object sender, RoutedEventArgs e)
        {
            cmbSpecialHandling.BorderBrush = Brushes.Transparent;
        }
于 2010-12-13T10:19:34.990 回答
1

在其中设置组合框的边框画笔Gotfocus并使其在失去焦点时透明:

private void comboBox_GotFocus(object sender, RoutedEventArgs e)
    {
        Thickness th = new Thickness(2);
        comboBox.BorderThickness = th;
        comboBox.BorderBrush = this.FindResource("TabFocusColor") as SolidColorBrush;
                  or
     comboBox.BorderBrush = Brushes.Green;
    }


    private void comboBox_LostFocus(object sender, RoutedEventArgs e)
    {
        comboBox.BorderBrush = Brushes.Transparent;
    }
于 2010-12-13T10:36:15.947 回答