我的XAML需要花费很长时间才能加载。我完全不知道为什么。我已经尝试了所有方法,从删除Grid
到评论整个MyContext
,看看它是否是绑定。纳达。加载只需要一段时间。可能是因为我在XAML中做错了。当我在运行时打开它时,它需要1秒左右没有修复,这是正常的,因为它必须进行数据库调用。
无论如何,这是违规的XAML,删除了内部信息:
<Window x:Class="MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lcl="clr-MyNamespace"
Title="New User" Height="300" Width="500" ResizeMode="NoResize">
<Window.DataContext>
<lcl:MyContext/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label Content="Data:" Grid.Column="1" Grid.Row="1"/>
<TextBox Grid.Column="2" Grid.Row="1"/>
<Label Content="More Data:" Grid.Column="1" Grid.Row="3"/>
<TextBox Grid.Column="2" Grid.Row="3"/>
<Label Content="Even More Data:" Grid.Column="1" Grid.Row="5"/>
<TextBox Grid.Column="2" Grid.Row="5"/>
<Label Content="Selectable Data:" Grid.Column="4" Grid.Row="1"/>
<Grid Grid.Column="4" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" BorderThickness="0">
<Viewbox>
<Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="38" Height="38" Canvas.Left="19" Canvas.Top="19" Stretch="Fill" Fill="#FF000000" Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "/>
</Canvas>
</Viewbox>
</Button>
</Grid>
<ListBox Grid.Column="4" Grid.Row="3" Grid.RowSpan="3" ItemsSource="{Binding MySelectableData}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name, StringFormat='Name: {0}}'}"/>
<TextBox Text="{Binding EmailAddress, StringFormat='Email Address: {0}'}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Content="Cancel" Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="2" Margin="0,0,85,0"/>
<Button Content="OK" Grid.Column="4" Grid.Row="7"/>
</Grid>
</Window>