ARCGIS PRO SDK ProWindow自定义窗口DataGrid控件的应用

ProWindow 是ArcGIS Pro SDK中用于创建自定义窗口的关键类,帮助开发者扩展ArcGIS Pro的功能和用户界面。这些窗口可以嵌入到ArcGIS Pro的主界面中,提供与核心功能的无缝集成。

创建一个窗体xml:

复制代码
controls:ProWindow
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:controls="clr-namespace:ArcGIS.Desktop.Framework.Controls;assembly=ArcGIS.Desktop.Framework"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:extensions="clr-namespace:ArcGIS.Desktop.Extensions;assembly=ArcGIS.Desktop.Extensions"
        xmlns:VisualBasic="clr-namespace:Microsoft.VisualBasic;assembly=Microsoft.VisualBasic.Core" x:Class="ProWindow1"
        mc:Ignorable="d"
        Title="绘制图例" Height="320" Width="530" 
        WindowStartupLocation="CenterOwner"
    >
    <controls:ProWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <extensions:DesignOnlyResourceDictionary Source="pack://application:,,,/ArcGIS.Desktop.Framework;component\Themes\Default.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </controls:ProWindow.Resources>
    <Grid>
        <GroupBox Header="地图图层" FontSize="10" HorizontalAlignment="Left" VerticalAlignment="Top" Width="225" Height="250 " Margin="3,0,0,0">
            <StackPanel>
                <DataGrid x:Name="DataGrid1" FontSize="9" AutoGenerateColumns="False" ScrollViewer.VerticalScrollBarVisibility="Visible"  HorizontalAlignment="Left" VerticalAlignment="Top" Width="210" Height="230 " Margin="2,0,0,0">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="图层名称" Width="85" Binding="{Binding tc_name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                        <DataGridCheckBoxColumn Header="参与?" Width="35"  Binding="{Binding sf_cy}"/>
                        <DataGridTemplateColumn Header="字段名称" Width="65">
                            <DataGridTemplateColumn.CellTemplate >
                                <DataTemplate>
                                    <ComboBox ItemsSource="{Binding AvailableCategories}"
                                              DisplayMemberPath="zd_Namea"
                                              SelectedValuePath="zd_ID"
                                              SelectedValue="{Binding zd_nameID ,Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}" /> 
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                    <!-- 标头居中 -->
                    <DataGrid.ColumnHeaderStyle>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        </Style>
                    </DataGrid.ColumnHeaderStyle>
                </DataGrid>
            </StackPanel>
        </GroupBox>
        <Button x:Name="Button1" FontSize="9" Content="获取图层" Height="18" Width="45" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="78,257,0,0" />
    </Grid>
</controls:ProWindow>

允许效果:

设置DataGrid表字段名称列为下拉框,DataGridTemplateColumn 设置ComboBox动态绑定。

vb.net ,定义Person1类,用于DataGrid1设置数据源类型

复制代码
Imports System.Collections.ObjectModel
Public Class Person1                '用于DataGrid1设置数据源
    Public Property tc_name As String
    Public Property sf_cy As Boolean
    Public Property zd_name As String
    Public Property zd_nameID As Integer ' 用于绑定选中的 zd_name
    Public Property AvailableCategories As List(Of Zd_name)
    Public Sub New(tc_name As String, sf_cy As Boolean, zd_name As String, zd_nameID As Integer, AvailableCategories As List(Of Zd_name))
        Me.tc_name = tc_name
        Me.sf_cy = sf_cy
        Me.zd_name = zd_name
        Me.zd_nameID = zd_nameID
        Me.AvailableCategories = AvailableCategories
    End Sub
End Class

定义ComboBox动态绑定类

复制代码
Public Class Zd_name
    Public Property zd_ID As Integer
    Public Property zd_Namea As String
End Class

在窗体类中

复制代码
Public Class ProWindow1
    Inherits ArcGIS.Desktop.Framework.Controls.ProWindow
    Private people_1 As New ObservableCollection(Of Person1)()
    Public Property Categories As ObservableCollection(Of Zd_name)
    Public Sub New()
           InitializeComponent()
           DataGrid1.ItemsSource = people_1
    End Sub
    Dim pmap As Map
    Dim dict(50) As List(Of FieldDescription)
    Dim pFeatureLayer As FeatureLayer
    Dim pFeature As Feature
    Dim PFeatureClass As FeatureClass
    Dim pFeatCursor As RowCursor
    Private Async Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
        Dim pMapView As MapView = MapView.Active
        Dim collection As ObservableCollection(Of Person1) = DirectCast(DataGrid1.ItemsSource, ObservableCollection(Of Person1))
        Dim jsq As Integer = -1

        If collection IsNot Nothing Then
            collection.Clear()  ' 直接清空集合
        End If
        DataGrid1.CanUserAddRows = True  '将CanUserAddRows重新设置为True,这样DataGrid就会自动生成新行,我们就能在新行中输入数据了。
        If pMapView Is Nothing = True Then
            MsgBox("当前打开的不是激活的地图.")
            Exit Sub
        End If
        Dim pmap As Map = pMapView.Map
        Dim categories(100) As List(Of Zd_name)
        Dim jsq1 As Integer = 0
        For i = 0 To pmap.Layers.Count - 1
            If pmap.Layers(i).GetType.Name = "FeatureLayer" Then
                jsq += 1
                pFeatureLayer = pmap.Layers(i)
                dict(jsq) = New List(Of FieldDescription)
                Await QueuedTask.Run(Sub()
                                         dict(jsq) = pFeatureLayer.GetFieldDescriptions
                                     End Sub)
                jsq1 = 0
                categories(jsq) = New List(Of Zd_name)
                For Each ttsr In dict(jsq)
                    jsq1 += 1
                    categories(jsq).Add(New Zd_name() With {.zd_ID = jsq1, .zd_Namea = ttsr.Name})
                Next
                people_1.Add(New Person1(pmap.Layers(i).Name, False, "", 1, categories(jsq)))
            End If
        Next
        DataGrid1.ItemsSource = people_1
    End Sub
End Class

运行结果:

读取DataGrid表:vb.net

复制代码
        Dim tc_mc As String
        Dim tc_cy As Boolean
        Dim zd_id As Integer = 0
        Dim tc_zd As String
        Dim tc_zdZ() As String
        Dim zdzs As Integer
        Dim tl_id As Integer = 0
        For Each row As Person1 In DataGrid1.Items
             tc_mc = row.tc_name          ' DataGrid第一列
             tc_cy = row.sf_cy            ' DataGrid第二列
             zd_id = row.zd_nameID        ' DataGrid第三列  :ComboBox选中的ID
             tc_zd = GetCategoryNameByID(zd_id, row.AvailableCategories)  'ComboBox下拉框元素集合
        next

自定义函数:

复制代码
Private Function GetCategoryNameByID(categoryID As Integer, categories As List(Of Zd_name)) As String
    Dim category As Zd_name = categories.FirstOrDefault(Function(c) c.zd_ID = categoryID)
    Return If(category IsNot Nothing, category.zd_Namea, "Unknown")
End Function
相关推荐
敲敲敲-敲代码2 小时前
【ArcGIS操作】ArcGIS 进行空间聚类分析
arcgis
xa138508692 天前
ARCGIS PRO SDK VB2022 图层要素类类型判断
arcgis
weixin_贾3 天前
AI辅助下基于ArcGIS Pro的SWAT模型全流程高效建模实践与深度进阶应用
arcgis·swat模型·面源污染
赵钰老师4 天前
【Nature顶刊级科研绘图】DeepSeek、ChatGPT等大语言模型绘图(如何画图、如何标注、如何改图、如何美化、如何组合、如何排序)
人工智能·arcgis·信息可视化·语言模型·r语言
xa138508696 天前
ARCGIS PRO SDK 创建右键菜单
arcgis
GISBox7 天前
PLY格式文件如何转换成3DTiles格式——使用GISBox软件实现高效转换
arcgis·信息可视化·node.js·gis·webgl·cesium
啊喔啊喔R8 天前
arcgispro加载在线地图
arcgis
树谷-胡老师9 天前
用ArcGIS做一张符合环评要求的植被类型图
arcgis
称昵写填未9 天前
基于ArcGIS和ETOPO-2022 DEM数据分层绘制全球海陆分布
人工智能·经验分享·arcgis·dem