如果这是另一个问题的重复,我很抱歉,但我完全难过,并没有看到任何与我的具体问题有关的内容。
class ErrorTicketDisplay
{
public ErrorTicket[] tickArray1 = new ErrorTicket[1];
internal ErrorTicket[] tickArray2 = new ErrorTicket[1];
public ErrorTicketDisplay(List<ErrorTicket> tickets, int o)
{
tickArray1 = tickets.ToArray();
String errorDisplayString = "";
ErrorDisplay errorForm = new ErrorDisplay();
MergeSort(o, tickArray1, 0, tickArray1.Length - 1);
foreach (ErrorTicket tick in tickArray1)
{
errorDisplayString += tick.toString() + "\r\n";
errorForm.errorBlock.Height += 16;
}
if (!errorDisplayString.Equals(""))
{
errorForm.errorBlock.Text = "Results:" + "\r\n";
errorForm.errorBlock.Text += errorDisplayString;
}
else if (errorDisplayString.Equals(""))
{
errorForm.errorBlock.Text = "Results:" + "\r\n";
errorForm.errorBlock.Text += "No Issue Tickets Found";
}
errorForm.Show();
}
}
ErrorDisplay对象是一个标准的Wpf窗口,包含一个文本块“errorBlock”来保存一串结果和几个按钮。问题在于,在任何一个if语句中,Textblock的内容都会更新,但是当它离开语句并且我尝试显示表单时,内容会清空,我只剩下一个空白框并且纽扣。为什么会发生这种情况,如何在正确显示之前更新文本块的内容?我正在运行Visual Studio 2013,如果这有任何区别的话。
编辑:这是xaml标记:
<Window x:Class="WpfApplication1.UIWindows.ErrorDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ErrorDisplay" Height="300" Width="300">
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="240" Margin="0,0,0,40">
<TextBlock x:Name="errorBlock" HorizontalAlignment="Left" TextWrapping="Wrap"
Text="TextBlock" VerticalAlignment="Top" Height="0" Width="292" Margin="0,0,0,0"/>
</ScrollViewer>
<Button x:Name="close" Content="Close" HorizontalAlignment="Left"
Margin="207,239,0,0" VerticalAlignment="Top" Width="75" Click="buttonClick"/>
<Button x:Name="newAudit" Content="New Audit" HorizontalAlignment="Left"
Margin="127,239,0,0" VerticalAlignment="Top" Width="75" Click="buttonClick"/>
<Button x:Name="errorCodes" Content="Error Codes" HorizontalAlignment="Left"
Margin="10,239,0,0" VerticalAlignment="Top" Width="75" Click="buttonClick"/>
</Grid>