【问题标题】:horizontal alignment to the right + wpf向右水平对齐+ wpf
【发布时间】:2012-09-12 15:30:47
【问题描述】:

我有一个窗口 wpf 应用程序,显示项目列表。 我希望将列表显示在右侧,而不是像目前那样显示在左侧。 附上我的部分 xaml 文件。 我尝试将属性水平对齐附加到文本块和图像,但没有任何改变。

   <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>

我感谢您提供的任何帮助。 谢谢,哈达斯。

【问题讨论】:

    标签: c# wpf wpf-controls alignment


    【解决方案1】:
    <Grid>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="Auto"/>
     </Grid.ColumnDefinitions>
     <StackPanel Grid.Column="1" />
    </Grid>
    

    您可以在堆栈面板上方引入一个网格并使用第 1 列来获得右对齐

    【讨论】:

      【解决方案2】:

      使用DockPanel 代替StackPanel 并尝试设置HorizontalContentAlignment

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 2015-07-02
        • 2012-12-07
        • 1970-01-01
        相关资源
        最近更新 更多