0
我有我想要顯示的DockPanel中內,但一些信息,它超出在DockPanel中和一些文字行得到切斷這樣的:WPF C#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);