2011-05-14 7 views
19

उदाहरण के लिए, ध्यान दें कि पाठ कॉम्बोबॉक्स के ऊर्ध्वाधर केंद्र में बिल्कुल नहीं है।मैं कॉम्बोबॉक्स की सामग्री को लंबवत कैसे केंद्रित कर सकता हूं?

enter image description here

यहाँ मेरी XAML है:

<Window x:Class="_24HoursBook.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="450" Width="350" MinHeight="450" MinWidth="350"> 


    <Grid ShowGridLines="True"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="0.15*" /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 
     <Image Grid.Row="0" Stretch="Fill" Source="Image/topBarBg.png" /> 
     <StackPanel Orientation="Horizontal" Grid.Row="0">    
      <TextBlock Text="Platform" 
         Foreground="White" 
         FontFamily="Georgia" 
         FontSize="15" 
         Margin="10" 
         HorizontalAlignment="Center" 
         VerticalAlignment="Center"/> 
      <ComboBox x:Name="cmbPlatform" 
         Margin="10" 
         FontFamily="Georgia" 
         FontSize="15" 
         MinHeight="30" 
         MinWidth="140" 
         VerticalAlignment="Center"> 
       <ComboBoxItem>All Platforms</ComboBoxItem> 
       <ComboBoxItem>Playstation 3</ComboBoxItem> 
       <ComboBoxItem>XBox 360</ComboBoxItem> 
       <ComboBoxItem>Wii</ComboBoxItem> 
       <ComboBoxItem>PSP</ComboBoxItem> 
       <ComboBoxItem>DS</ComboBoxItem> 
      </ComboBox>    
     </StackPanel> 
     <Image Grid.Row="0" Source="Image/about.png" 
       Height="16" HorizontalAlignment="Right" 
       VerticalAlignment="Center" 
       Margin="0 0 10 0" /> 

     <ListView Grid.Row="1" Background="#343434"> 

     </ListView> 
    </Grid> 
</Window> 

मैं WPF करने के लिए एक तरह से नई हूँ, और मैं वास्तव में शुरू से ही कुछ भी इसके साथ समाप्त करने के लिए कभी नहीं किया है। मैं आपको पकड़ने वाली कुछ चमकदार नौसिखियों की गलतियों को सुधारने के लिए किसी भी सुझाव की सराहना करता हूं।

उत्तर

40

अपने combobox में VerticalContentAlignment="Center" जोड़ें।

+0

मैं कम्बोबॉक्स क्षैतिज केंद्र की सूची आइटम दिखाना चाहता हूं – Meer

2

आप इसके साथ खेलने के लिए है, लेकिन लगता है कि अगर मैं था:

<ComboBox x:Name="cmbPlatform" 
        Margin="10" 
        FontFamily="Georgia" 
        FontSize="15" 
        MinHeight="30" 
        MinWidth="140" 
        VerticalAlignment="Center" 
        VerticalContentAlignment="Center"> 

अपेक्षाकृत कम संख्या को MinHeight="30" बदलने का प्रयास करें। हो सकता है कि आप पाठ से बड़े बॉक्स को बना रहे हों। पाठ लाइन पर केंद्रित है लेकिन बॉक्स बड़ा है।

+0

ठीक है, combobox लंबवत केंद्रित है, मैं सहमत हूं। लेकिन मैं कम्बोबॉक्स के भीतर भी सामग्री को केंद्र में रखना चाहता हूं। –

+0

एक कॉम्बोबॉक्स Item के केंद्र में लंबवत संरेखण सेट करना कुछ भी नहीं करता है। –

+0

@ सर्जियो वर्टिकलकंटेंटलाइन – Hogan

3

यदि मैं अपना कोड कॉपी और पेस्ट करता हूं, तो पाठ मेरे लिए कॉम्बोबॉक्स के केंद्र में लंबवत रूप से गठबंधन होता है। क्या आप सुनिश्चित हैं कि आपके पास आपके एप्लिकेशन में कोई स्टाइल या टेम्पलेट सेट अप नहीं है जो आपके नियंत्रण में लागू हो रहा है और ऐसा हो रहा है?

संपादित करें: कभी नहीं।

<Style TargetType="{x:Type ComboBox}"> 
     <Setter Property="VerticalContentAlignment" Value="Center" /> 
</Style> 

तो जब मैं नकल की और में अपने कोड चिपकाया, यह मेरे लिए काम किया: मैं वास्तव में एक शैली अपने आवेदन में स्थापित था!