2017-12-12 10 views
2

편집 가능한 wpf 콤보 박스. 긴 문자열을 입력 할 때 텍스트 상자가 스크롤되지 않는 문제가 있습니다. 이 링크가 마음에 듭니다 Editable combobox text scrolling콤보 상자 텍스트 입력

TextBox.ScrollToHome()하지만 작동하지 않습니다.

가이 콤보 상자 WPF 기본값은 이미 당신이 원하는 기능이 내 코드와 my sample image

<Style TargetType="{x:Type ComboBox}" x:Key="autoComplateComboBox"> 
      <Setter Property="ScrollViewer.CanContentScroll" Value="True"/> 
      <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="True"/> 
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="UIElement.SnapsToDevicePixels" Value="True"/> 
      <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/> 
      <Setter Property="TextElement.Foreground" Value="Black"/>     
      <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/> 
      <Setter Property="ItemsPanel"> 
       <Setter.Value> 
        <ItemsPanelTemplate> 
         <VirtualizingStackPanel IsItemsHost="True" 
             VirtualizingStackPanel.IsVirtualizing="True" 
             VirtualizingStackPanel.VirtualizationMode="Recycling" 
             KeyboardNavigation.DirectionalNavigation="Contained"/> 
        </ItemsPanelTemplate> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="Control.Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="ComboBox"> 
         <Grid> 
          <ToggleButton Name="ToggleButton" Grid.Column="2" 
             ClickMode="Press" Focusable="False" Click="ToggleButton_Click" 
             IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Template="{StaticResource ComboBoxToggleButtonTemplate}"> 
          </ToggleButton> 
          <ContentPresenter Name="ContentSite" Margin="5, 3, 23, 3" IsHitTestVisible="False" 
              HorizontalAlignment="Left" VerticalAlignment="Center"        
              Content="{TemplateBinding ComboBox.SelectionBoxItem}" 
              ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" 
              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"> 
          </ContentPresenter> 

          <TextBox Name="txtInput" Margin="3, 3, 23, 3" IsReadOnly="{TemplateBinding IsReadOnly}" Visibility="Hidden" Background="Transparent" TextChanged="txtInput_TextChanged" SelectionChanged="txtInput_SelectionChanged"           
           HorizontalAlignment="Stretch" VerticalAlignment="Center" TextAlignment="Left" Focusable="True" GotFocus="txtInput_GotFocus" LostFocus="txtInput_LostFocus"> 
           <TextBox.Template> 
            <ControlTemplate TargetType="TextBox"> 
             <Border Name="PART_ContentHost" Focusable="False"/> 
            </ControlTemplate> 
           </TextBox.Template> 
          </TextBox> 

          <!-- Popup showing items --> 
          <Popup Name="PART_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="White" Margin="0, 1, 0, 0" 
             CornerRadius="0" BorderThickness="1,1,1,1" 
             BorderBrush="{StaticResource BasicNormalBorderBrush}"/> 
            <ScrollViewer Margin="4" SnapsToDevicePixels="True"> 
             <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" /> 
            </ScrollViewer> 
           </Grid> 
          </Popup> 
         </Grid> 
         ...... 
+0

에서 ScrollViewer-Border에서 PART_ContentHost 유형입니다 ... 비교 스타일에 기본 콤보 스타일을 적용하고 누락 된 부분을 확인하십시오. –

+0

나는 같은 생각을 가지고 있었지만 원하는 답을 얻었습니다. 답장을 보내 주셔서 감사합니다. – yong

답변

0

스위치 TextBoxControlTemplate

<TextBox Name="txtInput" Margin="3, 3, 23, 3" IsReadOnly="{TemplateBinding IsReadOnly}" Visibility="Hidden" Background="Transparent" TextChanged="txtInput_TextChanged" SelectionChanged="txtInput_SelectionChanged"           
    HorizontalAlignment="Stretch" VerticalAlignment="Center" TextAlignment="Left" Focusable="True" GotFocus="txtInput_GotFocus" LostFocus="txtInput_LostFocus"> 
    <TextBox.Template> 
     <ControlTemplate TargetType="TextBox"> 
      <ScrollViewer Name="PART_ContentHost" Focusable="False"/> 
     </ControlTemplate> 
    </TextBox.Template> 
</TextBox> 
+0

감사합니다 ~ !!! 잘 작동한다. – yong

+0

니스. 이 답변을 수락 된 것으로 표시하십시오. – Mikolaytis

+0

8 시간 전에 동의 버튼을 찾고있었습니다. 미안 .. ^^; 왼쪽 수표 이미지를 클릭 하시겠습니까? – yong