我有一个简单的WPF对话框,显示程序中发生的任何错误。它绑定的视图模型非常简单,只是一个文本属性和一个显示错误列表的列表属性。但是,当我在我的应用程序中显示此对话框时,它显示为空,它只是标题栏和一个完全白色的窗口。只要我调整窗口大小,所有内容就会正确填充。为什么会这样?这是窗口的构造函数:
public Wnd_Errors(string description, List<GamutError> ers)
{
InitializeComponent();
_myVM = new ErrorWindowVM()
{
DescriptionText = description,
Errors = ers,
};
DataContext = _myVM;
}
以下是窗口的整个XAML:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="SPTR.Gamut.Wnd_Errors"
mc:Ignorable="d"
Title="Gamut | Errors"
WindowStartupLocation="CenterScreen"
Icon="Images/Icon_Gamut.ico"
Height="442" Width="846">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SPECtrumStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Background="{StaticResource br_RibbonBackdrop}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="Images/Icon_Error.png" Margin="10" />
<TextBlock x:Name="tb_Desc" Grid.Column="1" FontWeight="Bold" Margin="5" Text="{Binding DescriptionText}"
TextWrapping="Wrap" />
</Grid>
<telerik:RadGridView Grid.Row="1" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" GridLinesVisibility="Horizontal"
CanUserFreezeColumns="False" EditTriggers="None" CanUserDeleteRows="False" CanUserInsertRows="False"
ItemsSource="{Binding Errors}" CanUserSelect="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Error Type" DataMemberBinding="{Binding ErrorTypeText}" />
<telerik:GridViewDataColumn Header="Message" DataMemberBinding="{Binding UIText}"
TextWrapping="Wrap" Width="*" />
<telerik:GridViewDataColumn Header="Internal Error" DataMemberBinding="{Binding ErrorTypeText}">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<ScrollViewer MaxWidth="800" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<TextBlock Text="{Binding InternalMessage, Mode=OneWay}" />
</ScrollViewer>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Stack Trace" DataMemberBinding="{Binding ErrorTypeText}"
IsVisible="{Binding ShowStackTrace}">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<ScrollViewer MaxHeight="250" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<TextBox Text="{Binding Stack, Mode=OneWay}" />
</ScrollViewer>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<CheckBox Grid.Row="2" Content="Show Stack Trace (for error reporting)"
IsChecked="{Binding ShowStackTrace, Mode=TwoWay}" Margin="5,3" />
<Grid Grid.Row="3" Background="{StaticResource br_BaseBar}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48*"/>
<ColumnDefinition Width="371*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0" Grid.Column="1">
<Button Margin="5" Content="OK" HorizontalAlignment="Right" Width="75" IsDefault="True"
x:Name="btn_OK" Click="btn_OK_Click" />
<Button Margin="5" Content="Cancel" HorizontalAlignment="Right" Width="75" IsCancel="True"
x:Name="btn_Cancel" Click="btn_Cancel_Click" />
</StackPanel>
<Button Content="Export to .xlsx" Width="100" Margin="5" HorizontalAlignment="Left"
x:Name="Button2" Click="Button2_Click" Grid.ColumnSpan="2" />
</Grid>
<Separator Grid.Row="2" VerticalAlignment="Bottom" Margin="-1" Background="{StaticResource Br_Orange}" />
</Grid>
</Window>
正如你所看到的,我甚至没有订阅任何窗口事件来拥有任何类型的自定义处理程序,可以抑制任何事情......
我甚至在哪里开始尝试调试它?这是应用程序中唯一执行此操作的窗口(至少是我遇到的唯一一个窗口)。