realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

ComboBox caret in IsEditable="True" mode after inputting, the character is set to the preface

12 Nov 2018, 18:28

Hi,
Noesis C++ v.2.1.0f1

ComboBox caret in IsEditable = "True" mode after inputting, the character is set to the prev char

sorry, I wrote the wrong branch
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: ComboBox caret in IsEditable="True" mode after inputting, the character is set to the preface

14 Nov 2018, 14:52

Hi, I'm testing the XamlPlayer that comes with official 2.1.0f1 release and trying the following simple xaml works fine:
<ComboBox Width="200" VerticalAlignment="Center" IsEditable="True">
    <ComboBoxItem Content="Item 1"/>
    <ComboBoxItem Content="Item 2"/>
    <ComboBoxItem Content="Item 3"/>
    <ComboBoxItem Content="Item 4"/>
    <ComboBoxItem Content="Item 5"/>
</ComboBox>
Can you please try that? What are you doing differently?
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: ComboBox caret in IsEditable="True" mode after inputting, the character is set to the preface

16 Nov 2018, 11:54

Hi,
This behavior was when redefining the ComboBox style
<UserControl x:Class="GeoSearchControl"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  UseLayoutRounding="True"
  FontFamily="../Themes/Fonts/#Verdana"
  x:Name="control">

  <UserControl.Resources>

    <SolidColorBrush x:Key="ComboBoxNormalBorderBrush" Color="#2f2f37" />
    <SolidColorBrush x:Key="ComboBoxNormalBackgroundBrush" Color="#212125" />
    <SolidColorBrush x:Key="ComboBoxDisabledForegroundBrush" Color="#888" />
    <SolidColorBrush x:Key="ComboBoxDisabledBackgroundBrush" Color="#eee" />
    <SolidColorBrush x:Key="ComboBoxDisabledBorderBrush" Color="#888" />

    <ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition Width="20" />
        </Grid.ColumnDefinitions>
        <Border Name="Border"
                BorderBrush="{StaticResource ComboBoxNormalBorderBrush}"
                CornerRadius="2" BorderThickness="0.5"
                Background="{StaticResource ComboBoxNormalBackgroundBrush}" />
        <Border Grid.Column="1" Margin="2,0,2,0" BorderBrush="#444" Name="ButtonBorder"
                CornerRadius="2" BorderThickness="0"
                Background="{StaticResource ComboBoxNormalBackgroundBrush}" />

        <Path Name="Arrow" Grid.Column="1"
              Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z"
              HorizontalAlignment="Center" Fill="#999"
              VerticalAlignment="Center" />
      </Grid>
      <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsMouseOver" Value="True">
          <Setter Property="Background" TargetName="ButtonBorder" Value="#454550"/>
        </Trigger>
        <Trigger Property="ToggleButton.IsChecked" Value="True">
          <Setter Property="Background" TargetName="ButtonBorder" Value="#606070"/>
          <Setter Property="Shape.Fill" TargetName="Arrow" Value="#FF8D979E"/>
        </Trigger>
        <Trigger Property="UIElement.IsEnabled" Value="False">
          <Setter Property="Background" TargetName="Border" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
          <Setter Property="Background" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
          <Setter Property="Border.BorderBrush" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBorderBrush}"/>
          <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/>
          <Setter Property="Shape.Fill" TargetName="Arrow" Value="#999"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="ComboBoxFlatStyle"  TargetType="{x:Type ComboBox}">
      <Setter Property="SnapsToDevicePixels" Value="True"/>
      <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
      <Setter Property="TextElement.Foreground" Value="#c0c0c0"/>
      <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
      <Setter Property="Control.Template">
        <Setter.Value>
          <ControlTemplate TargetType="ComboBox">
            <Grid>

              <ToggleButton Name="ToggleButton"
                  ClickMode="Press" Focusable="False"
                  IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                  Template="{StaticResource ComboBoxToggleButtonTemplate}"/>

              <ContentPresenter Name="ContentSite" Margin="3" IsHitTestVisible="False"
                                HorizontalAlignment="Left" VerticalAlignment="Center"
                                Content="{TemplateBinding ComboBox.SelectionBoxItem}"
                                ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
                                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/>
              <TextBox Name="PART_EditableTextBox" Margin="3,3,23,3"
                       IsReadOnly="{TemplateBinding IsReadOnly}"
                       Visibility="Hidden" Background="Transparent"
                       HorizontalAlignment="Left" VerticalAlignment="Center"
                       Focusable="True" >
                <TextBox.Template>
                  <ControlTemplate TargetType="TextBox" >
                    <Border Name="PART_ContentHost" Focusable="False"/>
                  </ControlTemplate>
                </TextBox.Template>
              </TextBox>
              <Button Width="20" HorizontalAlignment="Right" Margin="2,2,23,2"/>
              <!-- Popup showing items -->
              <Popup Name="Popup" Placement="Bottom"
                     Focusable="False" AllowsTransparency="True"
                     IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
                     PopupAnimation="Slide">
                <Grid Name="DropDown" SnapsToDevicePixels="True"
                      MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
                      MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
                  <Border Name="DropDownBorder" Background="#353545" Margin="0,1,0,0"
                          BorderThickness="1" BorderBrush="#707075"/>
                  <ScrollViewer Margin="4" SnapsToDevicePixels="True">
                    <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
                  </ScrollViewer>
                </Grid>
              </Popup>
            </Grid>

            <ControlTemplate.Triggers>
              <Trigger Property="ItemsControl.HasItems" Value="False">
                <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
              </Trigger>
              <Trigger Property="UIElement.IsEnabled" Value="False">
                <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/>
              </Trigger>
              <Trigger Property="ComboBox.IsEditable" Value="True">
                <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
                <Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
                <Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/>
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </UserControl.Resources>

  <UserControl.Style>

    <Style TargetType="{x:Type GeoSearchControl}">
      <Setter Property="Background" Value="Transparent" />
      <Setter Property="Padding" Value="2" />
      <Setter Property="SnapsToDevicePixels" Value="True" />

      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type GeoSearchControl}">
            <ComboBox Style="{StaticResource ComboBoxFlatStyle}" ItemsSource="{Binding ElementName=control, Path=SearchItems}" IsEditable="True"/>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </UserControl.Style>

</UserControl>
I changed the styles
problem solved
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: ComboBox caret in IsEditable="True" mode after inputting, the character is set to the preface

16 Nov 2018, 18:36

I was able to reproduce the problem.
It was related to the horizontal alignment of the TextBox inside the ComboBox template, if you change it to Stretch then it works as expected.
That was a bug we already solved for the next version.

Please mark this topic as solved if it is fine for you.

Who is online

Users browsing this forum: No registered users and 11 guests