2009-06-15 6 views
11

OK, je le livrerai: qu'est-ce que je dois changer à ce StackPanel ci-dessous afin qu'il place le:Pourquoi StackPanel ne place-t-il pas le bloc de texte à gauche et le bouton à droite dans Silverlight?

  • texte sur l'extrême gauche de la forme
  • bouton à l'extrême droite de la forme.

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> 

RÉPONSE:

Téléchargé Silverlight 3 toolkit qui a DockPanel, installé, System.Windows.Controls référencé, puis en suivant 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

Répondre

11

Vous pouvez utiliser dockpanel à partir de la boîte à outils ou utiliser une grille avec 2 colonnes. et ont le contenu de la deuxième colonne aligné à droite

7

Voulez-vous dire que vous voulez que le bouton soit aligné à droite du formulaire? Si c'est le cas, StackPanel ne le fera pas. Il est fait pour "empiler les choses" horizontalement ou verticalement.

Je vous suggère d'essayer DockPanel:

<DockPanel> 
    <TextBlock x:Name="ProgressIndicator" 
       DockPanel.Dock="Left" 
       Text="Ready..." /> 
    <Button DockPanel.Dock="Right" 
      Content="Load Data" 
      Width="100" 
      Click="Button_Load" 
      Margin="0,5,0,0" /> 
</DockPanel> 
+0

oui, c'est la façon dont je le fais dans WPF mais je suis en utilisant Silverlight au moment, bien que Silverlight 3, désolé de voir il n'y a pas de dockpanel dans cette version, la recherche d'une solution de contournement ... –

+1

Je suis assez sûr que la boîte à outils de contrôle Silverlight a un dockpanel –

+0

Silverlight n'a pas de DockPanel? Je dois accorder plus d'attention aux étiquettes des questions. J'ai automatiquement supposé que c'était une question de WPF, mais je n'avais aucune idée qu'il n'y avait pas de DockPanel dans Silverlight! –

1

Je pense que l'approche de Matt le meilleur. Deux alternatives sont cependant d'utiliser une grille et d'aligner le contenu à gauche et à droite ou simplement de donner au bouton une très grande marge.

1

Référence devrait être:

xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
Questions connexes