2011-11-19 13 views
14

मेरे पास मेरे लिस्टबॉक्स के आसपास कुछ अतिरिक्त जगह है। यह 1px विस्तृत है, लेकिन मैं नहीं जानता कि यह कहाँ से आता है ...सूची बॉक्स के चारों ओर अतिरिक्त स्पेस निकालें

The black arrows show the extra space

मैं गद्दी, मार्जिन और दोनों की BorderThickness, ListBox और 0.

यह करने के लिए ListboxItem सेट एक्सएएमएल है:

<!-- NOTEBOX LISTBOX --> 

<!-- The Datatemplate for the Notebox - ListboxItem --> 
<DataTemplate x:Key="NoteListboxItemTemplate" DataType="ListBoxItem"> 
    <Border Style="{DynamicResource OuterNoteBoxBorder}"> 
     <Border Style="{DynamicResource SecondOuterNoteBoxBorder}"> 
      <StackPanel> 
       <TextBlock Grid.Column="0" Foreground="#225588" Text="{Binding Title}" Style="{DynamicResource PlayListListBoxTitleLabel}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" ></TextBlock> 
       <ContentPresenter Content="{Binding NoteView}"></ContentPresenter> 
       <TextBlock Grid.Column="1" Foreground="Black" Text="{local:CultureAwareBinding CreationDate, StringFormat={}{0:F}}" Style="{DynamicResource PlayListListBoxTitleLabel}"></TextBlock> 
      </StackPanel> 
     </Border> 
    </Border> 
</DataTemplate> 

<!-- The Itemtemplate for the Notebox - ListboxItem --> 
<Style x:Key="NoteboxListItemTemplate" TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="Margin" Value="0" /> 
    <Setter Property="Padding" Value="0" /> 
    <Setter Property="Foreground" Value="Black" /> 
    <Setter Property="Background" Value="White" /> 
    <Setter Property="BorderThickness" Value="0" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsSelected" Value="true"> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> 
         <!--<Setter Property="Background" TargetName="Bd" Value="#66000000"/> 
         <Setter Property="BorderBrush" Value="#000000" />--> 
        </Trigger> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="IsSelected" Value="true"/> 
          <Condition Property="Selector.IsSelectionActive" Value="false"/> 
         </MultiTrigger.Conditions> 
         <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>--> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
        </MultiTrigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Style.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#88000000"/> 
     <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
    </Style.Resources> 
</Style> 

<!-- The Border-Template for our Notebox - ListboxItem --> 
<Style x:Key="NoteboxListItemBorderTemplate" TargetType="{x:Type Border}"> 
    <Setter Property="Background" Value="#CCFFFFFF" /> 
    <Setter Property="Margin" Value="0" /> 
    <Setter Property="Padding" Value="0" /> 
    <Style.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#88000000"/> 
     <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#44000000"/> 
    </Style.Resources> 
</Style> 

<!-- Notebox - Listbox Template --> 
<Style x:Key="NoteboxListboxTemplate" TargetType="{x:Type ListBox}"> 
    <Setter Property="Background" Value="Transparent" /> 
    <Setter Property="BorderBrush" Value="Transparent" /> 
    <Setter Property="BorderThickness" Value="0" /> 
    <Setter Property="Padding" Value="0" /> 
    <Setter Property="Margin" Value="0" /> 
</Style> 


     <ListBox Grid.Column="1" 
      Grid.Row="0" 
      Background="Black" 
      MouseDoubleClick="ListBox_MouseDoubleClick" 
      HorizontalContentAlignment="Stretch" 
      ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
      ItemContainerStyle="{DynamicResource NoteboxListItemTemplate}" 
      VirtualizingStackPanel.VirtualizationMode="Recycling" 
      VirtualizingStackPanel.IsVirtualizing="True" 
      ItemsSource="{Binding Notes, Mode=TwoWay}" 
      ItemTemplate="{DynamicResource NoteListboxItemTemplate}" 
      SelectedItem="{Binding SelectedNote}" 
      Style="{DynamicResource NoteboxListboxTemplate}"> 
    </ListBox> 

मुझे क्या याद आ रही है?

उत्तर

10

एक ListBox के नियंत्रण टेम्पलेट इस तरह दिखता है:

<ControlTemplate x:Key="ListBoxControlTemplate1" TargetType="{x:Type ListBox}"> 
     <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="True"> 
      <ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}"> 
       <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
      </ScrollViewer> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
      </Trigger> 
      <Trigger Property="IsGrouping" Value="True"> 
       <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

सूचना पैडिंग = "1" सीमा पर Bd नामित:

<ControlTemplate TargetType="{x:Type ListBox}"> 
    <Border Name="Bd" 
      Background="{TemplateBinding Background}" 
      BorderBrush="{TemplateBinding BorderBrush}" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      SnapsToDevicePixels="true" 
      Padding="1"> <!-- This might be the problem --> 
    <!-- ... --> 
+0

येप, यह है! मैंने इस टेम्पलेट को लागू किया, और सब कुछ ठीक काम करता है! http://msdn.microsoft.com/de-de/library/ms754242(v=vs.90).aspx –

+0

@DanielGilbert: lol @ जर्मन लिंक, आपका नाम बहुत जर्मन नहीं लगता है। –

+0

अप्स - उस स्थानीयकरण को भूल गए। ^^ Yepp, लोग अक्सर इस पर ठोकर खा जाते हैं। : पी –

22

यह ListBox के लिए डिफ़ॉल्ट नियंत्रण टेम्पलेट है। चूंकि यह हार्कोड किया गया है और टेम्पलेट बाध्य नहीं है, तो आप या तो सूची बॉक्स को फिर से जोड़ सकते हैं और पैडिंग को 0 पर सेट कर सकते हैं, या चूंकि स्कॉलवियर पर पैडिंग में सूची बॉक्स के पैडिंग के लिए टेम्पलेट बाइंडिंग है, तो आप अपने लिस्टबॉक्स पर पैडिंग को -1 तक सेट कर सकते हैं सीमा पर पैडिंग ऑफसेट करें।

+4

"-1" का उल्लेख करने के लिए धन्यवाद। :) –

संबंधित मुद्दे