0
我從數據庫填充了一些文本(我將它們命名爲問題),但在我的包裝面板中,我只能顯示3個問題,剩下的問題被截斷,我有3個以上問題,我如何在包裝面板中進行分頁以在面板本身上顯示問題的其餘部分?我填充的問題for循環是這樣的:WPF C#在包裝面板中尋呼
for(int i= 0 ; i<lstQuestion.Count()-2; i++)
{
TextBlock tb = new TextBlock(); // Question
tb.FontSize = 19;
tb.FontWeight = FontWeights.Bold;
tb.Text = lstQuestion[i].QuestionContent;
tb.TextWrapping = TextWrapping.Wrap;
wrapPanel1.Children.Add(tb);
TextBox tbox = new TextBox();
if (lstQuestion[i].Answer.Trim().Length > 0) // Textbox for user to input answer in every question
{
tbox.FontSize = 19;
tbox.Width = 250;
tbox.Height = 50;
tbox.PreviewDrop += new DragEventHandler(tbox_PreviewDrop);
tbox.Focusable = false; // Disallow user to input anything into it.
wrapPanel1.Children.Add(tbox);
}
answers.Add(lstQuestion[i].Answer);
if (lstQuestion[i].QuestionNo != lstQuestion[i + 1].QuestionNo) // add spacing between question
{
StackPanel sp = new StackPanel();
sp.Width = 1010;
wrapPanel1.Children.Add(sp);
Label spacing = new Label();
spacing.Width = 1010;
spacing.Content = "";
wrapPanel1.Children.Add(spacing);
}
} // end of for each loop.
在我的XAML:
<Grid>
<WrapPanel HorizontalAlignment="Center" Name="wrapPanel1" VerticalAlignment="Center" Height="400" Width="1038" Margin="0,77,0,43" />
<WrapPanel Height="80" HorizontalAlignment="Center" Name="wrapPanel2" VerticalAlignment="Top" Background="Aquamarine" Width="1000">
</WrapPanel>
<Button Content="Check" Height="37" HorizontalAlignment="Center" Name="button1" VerticalAlignment="Bottom" Width="90" FontSize="24" Margin="474,0" Click="button1_Click" />
</Grid>
Wrappanel1是我把我的問題,並在文本框(畫布面板1是我想做的面板分頁),wrappanel2是另一個可以選擇答案的面板。
你可以從灰色箭頭看到,還有更多的文字,但它只是在滾動結束停在那裏。
您好感謝快速回復安排在XAML你的用戶界面,並把一個ScrollViewer中使所有文字可以看出?是的,scrollviewer確實有效,但並不是所有的文本都可以看到,只有一些,但之前使用scrollviewer之前更多 – user2376998
我個人不喜歡使用邊距和靜態高度和寬度來排列UI。所以請嘗試從ScrollViewer中刪除Margin,看看它是否有效。 – Nitesh
是的,我刪除了保證金,保證金默認設置,每當我刪除它,再次運行它,它會重新出現 – user2376998