silverlight - 为什么 StackPanel 不会在 Silverlight 中将文本 block 放在左侧,将按钮放在右侧?

标签 silverlight xaml stackpanel

好吧,我放弃了:我要改成这个堆栈面板 下面,以便它把:

  • 表格最左边的文字
  • 表单最右侧的按钮 .

  • alt text http://tanguay.info/web/external/stackPanelLeftRight.png
    <UserControl x:Class="TestData333.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Width="400" Height="300">
        <Grid x:Name="LayoutRoot" Background="White">
            <Border CornerRadius="10" Background="Yellow" Padding="20">
                <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
                    <ScrollViewer Background="Beige" 
                                  Height="230"
                                  Width="360">
                        <StackPanel>
                            <TextBlock x:Name="TheContent" 
                               Foreground="Navy"
                               FontSize="14"
                               TextWrapping="Wrap"/>
                        </StackPanel>
                    </ScrollViewer>
    
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name="ProgressIndicator" Text="Ready..."
                                   HorizontalAlignment="Left"/>
                        <Button Content="Load Data"
                            Width="100"
                            HorizontalAlignment="Right"
                            Click="Button_Load"
                            Margin="0 5 0 0"/>
                    </StackPanel>
    
                </StackPanel>
            </Border>
        </Grid>
    </UserControl>
    

    回答:

    已下载 Silverlight 3 toolkit它安装了 DockPanel,引用了 System.Windows.Controls,然后遵循 XAML:
    <UserControl x:Class="TestData333.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
        Width="400" Height="300">
        <Grid x:Name="LayoutRoot" Background="White">
            <Border CornerRadius="10" Background="Yellow" Padding="20">
                <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
                    <ScrollViewer Background="Beige" 
                                  Height="230"
                                  Width="360">
                        <StackPanel>
                            <TextBlock x:Name="TheContent" 
                               Foreground="Navy"
                               FontSize="14"
                               TextWrapping="Wrap"/>
                        </StackPanel>
                    </ScrollViewer>
    
                    <toolkit:DockPanel Margin="0 5 0 0">
                        <TextBlock toolkit:DockPanel.Dock="Left" x:Name="ProgressIndicator" Text="Ready..."
                                   FontSize="12"
                                   HorizontalAlignment="Left"/>
                        <Button toolkit:DockPanel.Dock="Right" Content="Load Data"
                            Width="100"
                            HorizontalAlignment="Right"
                            Click="Button_Load"/>
                    </toolkit:DockPanel>
    
                </StackPanel>
            </Border>
        </Grid>
    </UserControl>
    

    alt text http://tanguay.info/web/external/silverlightDockPanel.png

    最佳答案

    您可以使用工具包中的停靠面板或使用带有 2 列的网格。并使第二列的内容右对齐

    关于silverlight - 为什么 StackPanel 不会在 Silverlight 中将文本 block 放在左侧,将按钮放在右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/998673/

    相关文章:

    c# - 对于用户控件,如何设置项模板项到用户属性的绑定(bind)?

    c# 在 windows phone 8.1 silverlight 项目中混合两个音频文件

    c# - Xamarin Forms 为 Android 带来光明

    c# - 在 WPF 中,有没有办法制作像 Grid 一样具有对齐列的 StackPanel?

    具有多个固定高度部分和相对于窗口大小的某些部分的 WPF 布局

    .net - DisplayMemberPath 等属性成为依赖属性的原因/场景是什么?

    Silverlight 4 超出浏览器 : "Unable to determine the URL to the Xap file from web"

    c# - 如何在使用自定义窗口镶边时向 WPF 标题栏添加按钮?

    c# - 部分声明,不得指定不同的基类

    c# - WPF:禁用有界 ItemsControl 中的项目