Click here to Skip to main content
16,017,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
The code below does not align the text to right. If I do not use Window.Resources (I want to change color of the selected item) code works. Can you help me please?
HTML
<Window.Resources>
            <Style x:Key="_ListBoxItemStyle" TargetType="ListBoxItem">            
            <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Border Name="_Border"
                                Padding="2"
                                SnapsToDevicePixels="true">
                                <ContentPresenter />
                            </Border>
                            
                            
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter TargetName="_Border" Property="Background" Value="Gray"/>
                                    <Setter Property="Foreground" Value="Yellow"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>        
        </Style>
        </Window.Resources>
 <ListBox x:Name="myListBox" ItemContainerStyle="{DynamicResource _ListBoxItemStyle}" Margin="0,20,0,30" 
                 VerticalAlignment="Top" Width="800" HorizontalAlignment="Right"  MinHeight="200" ScrollViewer.HorizontalScrollBarVisibility="Disabled"  
                  SelectionChanged="myListBox_SelectionChanged" MouseDoubleClick="myListBox_MouseDoubleClick" Panel.ZIndex="2" 
                 BorderThickness="0" FontSize="15" Background="{x:Null}" 
                 HorizontalContentAlignment="Right">           
        </ListBox>


What I have tried:

The code below does not align the text to right. If I do not use Window.Resources (I want to change color of the selected item) code works. Can you help me please?
Posted
Comments
[no name] 19-Sep-20 12:09pm    
Add a HorizontalAlignment.Right to the ListBoxItem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900