简体   繁体   中英

horizontal alignment to the right + wpf

i have a window wpf application, presenting a list of items. i would like the list to be presented to the right, and not to the left as it is at the moment. my partly xaml file is attached. i tried attaching the attribute horizontalalignment to the textblocks and the images, but nothing changed.

   <HierarchicalDataTemplate DataType="{x:Type cl:FolderData}" ItemsSource="{Binding Path=Children,UpdateSourceTrigger=PropertyChanged}">
    <Border BorderThickness="1">
        <!-- Drop="FolderStackPanel_PreviewDrop" -->
        <StackPanel DragEnter="StackPanel_PreviewDragEnter" DragLeave="StackPanel_PreviewDragLeave" 
                         Name="FolderStackPanel" Drop="FolderStackPanel_PreviewDrop" Orientation="Horizontal" ContextMenu="{StaticResource cmExportDelete}"
                    HorizontalAlignment="Right">
            <Image Name="NodeIcon" Width="24"  Margin="5" Height="24" Source="pack://application:,,,/ExportToolWpf;component/Images/folder_icon.png"/>
            <StackPanel Orientation="Vertical" Margin="0,5,0,0" >
                <TextBlock Name="NodeHeader" FontSize="11" Text="{Binding Path=FolderName}" />
                <StackPanel Name="IdPanel" Orientation="Horizontal">
                    <TextBlock FontSize="10" Foreground="Gray" Text="Client ID:" />
                    <TextBlock FontSize="10" Foreground="Gray" Text="{Binding Path=ClientId}" Margin="0,0,7,0" />
                    <TextBlock FontSize="10" Foreground="Gray" Text="Project ID:"/>
                    <TextBlock FontSize="10" Foreground="Gray" Text="{Binding Path=ProjectId}" />
                </StackPanel>
            </StackPanel>
        </StackPanel>
    </Border> </HierarchicalDataTemplate>

i apriciate any help you can offer. thanks, hadas.

<Grid>
 <Grid.ColumnDefinitions>
  <ColumnDefinition Width="*"/>
  <ColumnDefinition Width="Auto"/>
 </Grid.ColumnDefinitions>
 <StackPanel Grid.Column="1" />
</Grid>

You can introduce a grid just above the stackpanel and use Column # 1 for obtaining right alignment

使用DockPanel而不是StackPanel并尝试设置HorizontalContentAlignment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM