2014-09-03 2 views
0

VerticalContentAlignment으로 설정된 콤보 박스가 Center으로 설정되었지만 여전히 가운데로 보이지 않습니다. 문제는 전체 텍스트가 아닌 소문자를 중심으로 처리된다는 것입니다. 따라서 This Is An Example과 같은 텍스트가 있고 소문자의 위쪽/아래쪽 공간을 측정하는 경우 e이 가운데 정렬됩니다. 그러나 대문자를 사용하면 더 많은 정렬이 이루어집니다. 많은 응용 프로그램에서 이것은 처리됩니다 .... WPF에서 이것을 처리 할 수있는 방법이 있습니까?콤보 박스가 시각적으로 중앙에 위치하지 않습니다.

+1

당신이 당신의 마크 업을 표시 할 수 있습니다 – MethodMan

답변

1

의 모양을 정의하려면 ComboBox.ItemTemplate property을 사용할 수 있습니다. 당신이 선택적으로 추가 옵션에 대한 Run.BaselineAlignment property을 사용할 수 있습니다, 그게 당신이 원하는 일을하지 않는 경우

<ComboBox ItemsSource="{Binding Items}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding}" VerticalAlignment="Center" /> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

:

<ComboBox ItemsSource="{Binding Items}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock VerticalAlignment="Center"> 
       <Run BaselineAlignment="TextBottom" Text="{Binding}" /> 
      </TextBlock> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

난 그냥했습니다 그런 다음 당신이 적합을 볼 것을 어쨌든 항목 내용을 정렬 할 수 있습니다 생각 ... 당신이 아니라 당신이이 TextBlock.Margin 또는 TextBlock.Padding 속성을 사용하여 원하는 텍스트를 배치 할 수 있습니다 :

<ComboBox ItemsSource="{Binding Items}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding}" Margin="0,2,0,0" /> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 
관련 문제