c# - 用户代码未处理常规转换 InvalidOperationException

标签 c# wpf xaml exception gis

我遇到了一个我完全不知道的问题。我收到以下错误消息:

The specified Visual and the Visual do not share a common ancestor, so there is no valid transformation between the two visuals.

当用户点击 map 上的一个点时调用。任何帮助,将不胜感激。我附上了错误的片段。如果您需要更多代码示例,请告诉我。

这是我的相关 XAML:

(<)inf:DialogWindowBase x:Class="Alliance.CommonUI.Views.Maps.EsriMapView"

<Grid>

<Grid>
 <DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">
                    <TextBlock Text="Content" Foreground="White" FontSize="12" />
                </DataTemplate>
                <esri:SimpleRenderer x:Key="MySimpleRenderer">
                    <esri:SimpleRenderer.Symbol>
                        <esri:SimpleFillSymbol Fill="#01FFFFFF" BorderBrush="#88000000" BorderThickness="2" />
                    </esri:SimpleRenderer.Symbol>
                </esri:SimpleRenderer>
 </Grid.Resources>

            <esri:Map x:Name="MyMap" Background="#FFE3E3E3" WrapAround="True" MouseClick="MyMap_MouseClick" MouseRightButtonDown="MyMap_MouseRightButtonDown" Extent="-9834972.92753924,4441899.425293319,-9833977.88119163, 4442762.485358352">
                <esri:ArcGISTiledMapServiceLayer ID="MyLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                <!--<esri:ArcGISLocalDynamicMapServiceLayer ID="Calvert_City" Path="C:\Users\jessical\Documents\ArcGIS\CalvertCity_Test.mpk"/>-->
                <esri:ArcGISDynamicMapServiceLayer  ID="Calvert_City" Url="http://localhost:6080/arcgis/rest/services/CalvertCity_Test_2/MapServer"/>
                <esri:FeatureLayer ID="MyFeatureLayer"  Url="http://localhost:6080/arcgis/rest/services/CalvertCity_Test_2/MapServer/0"
                            Renderer="{StaticResource MySimpleRenderer}" />
</esri:Map>

            <Border Background="{StaticResource PanelGradient}" BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="Left"  VerticalAlignment="Top"
            Margin="20" Padding="5" BorderBrush="Black" >
                <esri:Legend Map="{Binding ElementName=MyMap}"
                         LayerIDs="Calvert_City"
                         LayerItemsMode="Tree"
                         ShowOnlyVisibleLayers="False"
                         Refreshed="Legend_Refreshed">
                    <esri:Legend.MapLayerTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox Content="{Binding Label}"
                                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                    IsEnabled="{Binding IsInScaleRange}" >
                                </CheckBox>
                                <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
                            </StackPanel>
                        </DataTemplate>
                    </esri:Legend.MapLayerTemplate>
                    <esri:Legend.LayerTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Label}"
                            IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                            IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>
                        </DataTemplate>
                    </esri:Legend.LayerTemplate>
                </esri:Legend>
            </Border>
            <esri:InfoWindow x:Name="MyInfoWindow"
                         Padding="2"
                         CornerRadius="20"
                         Background="{StaticResource PanelGradient}"
                         Map="{Binding ElementName=MyMap}"
                         ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}"
                         MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />

enter image description here enter image description here

最佳答案

我在使用 SciChart 的第三方控件时遇到了这个错误。我发现错误是在幕后抛出的,调试器会让错误看起来好像没有被处理。但是,当我刚刚关闭这种类型异常的中断并在我的 catch 语句中放置一个断点时,异常并没有落入我的 catch block 中。我对所有这些感到有些困惑,但它似乎有效。

所以我的建议是让调试器不要中断这种类型的异常,看看它是如何工作的。

关于c# - 用户代码未处理常规转换 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298482/

相关文章:

c# - 如何在 C# 中获取 Azure DevOps 组织列表?

c# - 以编程方式更改 ScrollViewer 中的滚动条宽度

c# - 模型方法绑定(bind)在 xaml 中不起作用

即使应用了提供的解决方案,图像在具有 XAML 表单的 Android 项目中不可见 - Xamarin

c# - 更改位图图像的不透明度

c# - 如何在excel中创建一个可读的表格? C#

c# - XAML 菜单项可见但不可选择?

wpf - 如何以编程方式获取 WPF FrameworkElement 的当前视觉状态?

c# - 如何调整图像的标签 "inside"Xamarin Forms

c# - 与所有者实例的组合和交互