2016-08-23 7 views
-1

옵니다 칩 나는 텍스트 상자의 예에서 목록 상자를 추가 할 필요가

은 스크린 샷을 참조하십시오

public class Person 
{ 
    private ObservableCollection<string> _personList = new ObservableCollection<string>(); 

    public ObservableCollection<string> PersonList 
     { 
      get { return _personList; } 
      set 
      { 
       _personList = value; 
       if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("PersonList")); 
      } 
     } 

    private string _personStr = String.Empty; 

    public string PersonStr 
     { 
      get { return _personStr; } 
      set 
      { 
       _personStr = value; 
       if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("PersonStr")); 
      } 
     } 

    public Person() 
     { 
      PersonList.Add("IR-Punch"); 
      PersonList.Add("Stack-Overflow"); 
     } 

    public ICommand BTextCommand 
     { 
      get 
      { 
       return new DelegateCommand(AppendString); 
      } 
     } 

    public void AppendString() 
     { 
      PersonList.Add(PersonStr); 
     } 
} 

작동하는 XAML 소스 코드 :

<ItemsControl ItemsSource="{Binding PersonList}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding }" TextWrapping="Wrap"/> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

<TextBox Text="{Binding PersonStr}" Width="160" VerticalAlignment="Center" /> 

<Button Command="{Binding BTextCommand}" Content="Add" /> 

TextBox 내에 ListBox을 추가하는 것이 친절히 도움이됩니다. 나는시 틀을 돌봐. 나는 핵심 아이디어를 기대하고있다. 아래 그림과 같이

+0

코드에서 시도 할 수 있고 프로그래밍 방식으로 TextBox 내에 ListBox를 추가 할 수 있습니다. –

+0

그 글을 쓰는 방법을 묻는 아이디어입니다 ... –

+1

여기에 묻는 것은 약간 명확하지 않습니다. 텍스트 상자에 입력을 시작하고 드롭 다운에 옵션 목록을 표시 하시겠습니까? – Stewbob

답변

1

이 텍스트 상자 내에서 추가 컨트롤을 포함하지 마십시오 대신 스택 패널에서 ItemsControl에와 텍스트 상자를 포함 :

<Border BorderThickness="1"> 
    <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto"> 
     <StackPanel Orientation="Horizontal"> 
      <ItemsControl ItemsSource="{Binding PersonList}"> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <StackPanel Orientation="Horizontal"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <TextBlock Text="{Binding}"/> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl> 
      <TextBox MinWidth="100" BorderBrush="Transparent" BorderThickness="0" Text="{Binding PersonStr}" /> 
     </StackPanel> 
    </ScrollViewer> 
</Border> 

당신은 텍스트 상자처럼 보이도록 외부 테두리 스타일을 원할 것입니다 (정확한 BorderBrush를 찾는 것만으로)하지만, 요청에 따라 스타일을 남겨 두었습니다.

실제로이 방법을 시도해 보지 않고 접근해야하는 방식으로 작성했습니다. 문제가 있으면 알려주세요.

+0

감사합니다. 나는 이것을 시험해 본다. –