0

我有一些信息想在 DockPanel 中显示,但是它在 DockPanel 中超出了范围,并且一些文本像这样被截断:

在此处输入图像描述

我在后面的代码中填充它们,我如何设置停靠面板对齐方式,以便整个内容可以放置在其中而不会被切断。

这是xaml代码:

    <Grid Background="#FF5EC136">

    <DockPanel Height="894" HorizontalAlignment="Stretch" Margin="365,135,0,0" Name="dockPanel1" VerticalAlignment="Top" Width="1174" />
</Grid>

我不知道我的 xaml.cs 是否有用,所以我把它贴在这里大多数代码是不相关的:

      private void PopulateQuestion(int activityID, int taskID)
    {
      IList<Model.questionhint> lstQuestionHints = qh.GetRecords(taskID, activityID);

        StackPanel sp = new StackPanel();

        foreach (Model.questionhint qhm in lstQuestionHints)
        {
            StackPanel sp1 = new StackPanel() { Orientation = Orientation.Horizontal };
            TextBlock tb = new TextBlock();
            tb.Text = qhm.QuestionContent;
            tb.FontWeight = FontWeights.Bold;
            tb.FontSize = 24;
            sp1.Children.Add(tb);

            TextBox tbox = new TextBox();
            tbox.Width = 100;
            tbox.FontSize = 24;
            tbox.FontWeight = FontWeights.Bold;

            if (qhm.Option1.Trim().Length > 0 &&
               qhm.Option2.Trim().Length > 0)
            {

            sp1.Children.Add(tbox);

            }
           Label btn1 = new Label();
            Label btn2 = new Label();
            if (qhm.Option1.Trim().Length > 0)
            {

                btn1.Content = qhm.Option1;
                btn1.Width = 110;
                btn1.FontSize = 24;
                btn1.FontWeight = FontWeights.Bold;
                btn1.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFE22B2B"); 
                sp1.Children.Add(btn1);                                     
                btn1.MouseLeftButtonDown += (source, e) =>
                {
                    btn2.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFE22B2B"); 
                    btn1.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFF0FA08"); 
                    tbox.Text = btn1.Content.ToString();
                };

            }
            if (qhm.Option2.Trim().Length > 0)
            {

                btn2.Content = qhm.Option2;
                btn2.Width = 110;
                btn2.FontSize = 24;
                btn2.FontWeight = FontWeights.Bold;
                btn2.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFE22B2B");
                sp1.Children.Add(btn2);
                btn2.MouseLeftButtonDown += (source, e) =>
                {
                    btn1.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFE22B2B"); 
                    btn2.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#FFF0FA08"); 
                    tbox.Text =btn2.Content.ToString();
                };
            }

            sp.Children.Add(sp1);
        }
        dockPanel1.Children.Add(sp);
4

1 回答 1

1

使用 WrapPanel 而不是 StackPanel。替换代码中的以下行

StackPanel sp1 = new StackPanel() { Orientation = Orientation.Horizontal };

WrapPanel wp = new WrapPanel();
于 2013-07-12T03:18:08.717 回答