在我的WPF应用程序中,我创建了一个带有方向=水平的堆栈面板的底座面板。

我在堆栈面板上添加了一些按钮(如工具栏)

我希望能够将我的堆栈面板上的最后一个项目设置为附在窗口右侧。

一些图片以解释。

是)我有的 :



我将要拥有的:



这是我的XAML:

<DockPanel  Height="40" VerticalAlignment="Top" >
    <Border>

        <StackPanel Orientation="Horizontal" Background="{StaticResource DegradeCouleurTheme}">

            <Image  Source="ElipseGauche.png" Height="28" Margin="10,0,0,0" />

            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Goto_Premier">
                    <Image Source= "xRtDiva_XWPF_TBR_PREMIER.PNG_IMAGES.png" Height="16"/>
                </Button>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Goto_Precedent">
                    <Image Source= "xRtDiva_XWPF_TBR_PRECED.PNG_IMAGES.png" Height="16"/>
                </Button>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Goto_Suivant">
                    <Image Source= "xRtDiva_XWPF_TBR_SUIVANT.PNG_IMAGES.png" Height="16"/>
                </Button>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Goto_Dernier">
                    <Image Source= "xRtDiva_XWPF_TBR_DERNIER.PNG_IMAGES.png" Height="16"/>
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />


            <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />

            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Creer" >
                    <Image Source= "Toolbar_Creer.png" Height="16" />
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />

            <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />


            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Evenement_Supprimer">
                    <Image Source= "Toolbar_Supprimer.png" Height="16"/>
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />

            <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />


            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Evenement_Joints">
                    <Image Source= "Toolbar_FicJoints.png" Height="18"/>
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />

            <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />


            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Evenement_Annuler" >
                    <Image Source= "Toolbar_Annuler.png" Height="16"/>
                </Button>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_Evenement_Valider">
                    <Image Source= "Toolbar_Valider.png" Height="16"/>
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />



            <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />


            <StackPanel  Orientation="Horizontal" Height="28">

                <StackPanel.Background>
                    <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                </StackPanel.Background>

                <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_App_Parametrer" >
                    <Image Source= "Toolbar_Parametrer.png" Height="16"/>
                </Button>

            </StackPanel>

            <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />

            <Grid HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal" Height="28" >
                    <Image  Source="ElipseGauche.png" Height="28" Margin="15,0,0,0" />


                    <StackPanel  Orientation="Horizontal" Height="28">

                        <StackPanel.Background>
                            <ImageBrush ImageSource="ElipseMilieu.png"></ImageBrush>
                        </StackPanel.Background>

                        <Button Template="{StaticResource BoutonRessourcesTpl}" Click="Button_Click_About" >
                            <Label Margin="0,0,0,1" Foreground="White" Content="About" Height="16"  VerticalAlignment="Center" HorizontalAlignment="Center" Padding="0,0,0,0"/>
                        </Button>

                    </StackPanel>

                    <Image  Source="ElipseDroite.png" Height="28" Margin="0,0,0,0" />
                </StackPanel>
            </Grid>


        </StackPanel>

    </Border>
</DockPanel>


我试图在我的堆栈面板的最后一项上使用一个带有horizo​​ntalaligneemnt =的网格,但是它没有任何作用(这是逻辑!)

有人可以帮我吗?

非常感谢 :)

最佳答案

您不能使用堆栈面板执行此操作。您将需要使用网格来代替。

关于c# - 将stackPanel的最后一项水平附加到右侧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16319271/

10-11 11:23