SL4 TransformToVisual: "Value does not fall within the expected range."
I have a ScrollViewer containing a Canvas:
<ScrollViewer x:Name="scrollViewer" Margin="0" Grid.RowSpan="2" >
<i开发者_JAVA技巧:Interaction.Triggers>
<!-- stuff-->
</i:Interaction.Triggers>
<Border>
<Canvas x:Name="MapCanvas" Background="{Binding BackgroundColor}" Width="7200" Height="3200" >
<Canvas.RenderTransform>
<ScaleTransform />
</Canvas.RenderTransform>
<i:Interaction.Behaviors>
<!-- stuff-->
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<!-- stuff-->
</i:Interaction.Triggers>
</Canvas>
</Border>
This code causes an exception, "Value does not fall within the expected range."
var generalTransform = scrollViewer.TransformToVisual(MapCanvas);
Any hints on what causes this would be appreciated. Looking in the online help, I couldn't find documentation of what exceptions TransformToVisual might throw or why.
UPDATE: Is there q way to test the scrollViewer and/or MapCanvas to make sure the TransformToVisual call will succeed?
Maybe I am completely wrong but I suspect this could be a timing issue.
If I do
private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 20);
timer.Tick += (s, e2) =>
{
var generalTransform = scrollViewer.TransformToVisual(MapCanvas);
timer.Stop();
};
timer.Start();
}
the error doesn't occur anymore...
I guess it's because the controls haven't been 'visually' shown on the screen?
You can only call TransformToVisual on an element that is visible on the screen and already layed out
精彩评论