none
Cannot remove ListBoxItem padding RRS feed

  • Question

  • Dear all,

    I have a weird issue I cannot get ride of.

    I have a chart which is display as a ListBoxItem as seen in picture below :

    From the picture above it represent 2 charts that I need to be perfectly align from left. but as you can see the below chart, it is part of a listbox and it has on the left side a space which cause that chart not being align from top chart.

    I have try to set my itemsContainerStyle as below :

    <Style TargetType="ListBoxItem">
    						<Setter Property="HorizontalContentAlignment" Value="Stretch" />
    					<Setter Property="IsSelected" Value="{Binding IsChartSelected}" />
    					<Setter Property="Padding" Value="0"/>
    					<Setter Property="Template">
    						<Setter.Value>
    							<ControlTemplate TargetType="{x:Type ListBoxItem}">
    								<ContentPresenter/>
    							</ControlTemplate>
    						</Setter.Value>
    					</Setter>

    As you can see I am seetin the padding fro ListBoxItem to be 0, but still I have this spacing appears.

    Then I explore my visual tre by using Visual Studio Live visual tree feature to point out which object it shows. Then I notice it belongs to the ListBox.Scrollviewer which reserve some space between ListboxItem edges.

    I do not knoy what to do in order to remove this space .

    Any idea how or what I am doing wrong ?

    In case it cannot be remove, how can I get this space Width in order to bind it to my First top chart margin Left property ?

    Thanks for your precious help on this which drive me crazy.

    regards

    Thursday, April 26, 2018 3:17 PM

All replies

  • Hi wakefun,

    Could you please share a complete sample via OneDrive, which could reproduce the issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 27, 2018 9:11 AM
    Moderator
  • I cannot share a complete project as it is part of a confidential rules
    Friday, April 27, 2018 9:58 AM
  • Hi wakefun,

    >>Then I explore my visual tre by using Visual Studio Live visual tree feature to point out which object it shows. Then I notice it belongs to the ListBox.Scrollviewer which reserve some space between ListboxItem edges.

    Basically, checking the live property of ContenPresenter and its partner is the right direction.

    For example, in my demo, the ListBoxItem DataTemplate includes a Border element and StackPanel as its children:

    <DataTemplate x:Key="postBody">
                <Border BorderThickness="2" BorderBrush="Red">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Author}" />
                        <Button Margin="10,0,0,0" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, 
                        Path=DataContext.HideSigmaCursor, 
                        UpdateSourceTrigger=PropertyChanged}" >Click</Button>
                        <TextBlock Margin="10,0,0,0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, 
                        Path=DataContext.HideSigmaCursor, 
                        UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                </Border>
                
            </DataTemplate>

    The default Padding of Border is 4,1,4,1:

    We can remove the padding space by setting value to 0,0,0,0

    So if you have set the Padding in the Style, the most possible reason is the template of your third-party control has override this setting, you have to double-check it and re-write its template by yourself.

    If you can remove sensitive information and simplify project, it will be helpful.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 30, 2018 3:41 AM
    Moderator