我正在尝试编写一个用于测试图形应用程序的工具,基本上,这就是我的工作:
所以,当我正在编写自动化测试时,我需要等待Canvas在我开始在其上放置形状之前创建,我已经使用了Loaded事件,但没有创建任何形状。
我的问题是,什么时候开始在画布上放置元素?是否有除Loaded以外的特定事件?
编辑
好吧,事实上它不是一个Canvas,它是一个Grid,它充当了ListView的DataTemplate,Grid包含了很多孩子,我发现很难找到合适的时机来说它最终加载了所有它的孩子。
也许,我会继续检测父网格的可视树中的任何变化,如果在某段时间内没有检测到任何变化,那么,我认为所有的孩子都被加载和查看了?如果我决定以这种方式行走,那么可视树中的哪些事件会因每次新变化而被触发?
<Grid x:Class="Graphics.Stage.KPage" Name="Scaller"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlns:model="clr-namespace:Graphics.Models;assembly=Graphics.Models"
xmlns:p="clr-namespace:Graphics.Stage"
Cursor="None"
xmlns:Header_Footer="clr-namespace:Graphics.Stage.Header_Footer" AllowDrop="True" Width="{Binding Path=Width}" Height="{Binding Path=Height}" >
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Graphics.Stage;component/Resources/StageResources.xaml"/>
<ResourceDictionary Source="/Graphics.UserControls;component/SharedDictionaryGreen.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
<Grid.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=PagesList, Path=ScaleX}"
ScaleY="{Binding ElementName=PagesList, Path=ScaleY}"
></ScaleTransform>
</Grid.LayoutTransform>
<aero:SystemDropShadowChrome Name="ShadowChrome" Opacity="0.75" Margin="0,0,-5,-5" />
<Border BorderBrush="{StaticResource dark}" BorderThickness="1.5" Name="PageBorder" >
<Grid Name="Sizer" >
<Canvas Name="Layout" Background="{StaticResource light}" ClipToBounds="True" Cursor="None"/>
<Canvas Name="ImportedImageLayer" Background="Transparent" ClipToBounds="True" Cursor="None"/>
<p:InkSurface x:Name="LayerInkSurface" Cursor="None" />
<p:TempSurface x:Name="TempSurface0" Cursor="None" />
<p:TempSurface x:Name="TempSurface1" Cursor="None" />
<p:Surface x:Name="LayerOnTopTools" Cursor="None" >
</p:Surface>
<p:Surface x:Name="DraggingSurface0" Cursor="None" />
<p:Surface x:Name="DraggingSurface1" Cursor="None" />
<Header_Footer:HeaderFooterView x:Name="MyHeaderView" VerticalAlignment="Top" PictureVerticalAlignment="Top" MyVerticalAlignment="Top" />
<Header_Footer:HeaderFooterView x:Name="MyFooterView" VerticalAlignment="Bottom" PictureVerticalAlignment="Bottom" MyVerticalAlignment="Bottom" />
<Canvas Name="GridsCanvas" ClipToBounds="True" IsHitTestVisible="False">
</Canvas>
<p:TopViewLayer x:Name="PageTopView" ClipToBounds="True" />
</Grid>
</Border>
</Grid>
答案 0 :(得分:0)
如果在Canvas
事件后Loaded
尚未就绪,您可以尝试ContentRendered
事件。
ContentRendered += new EventHandler(MainWindow_ContentRendered);
private void MainWindow_ContentRendered(object sender, EventArgs e)
{
// do the dew
}