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
相关推荐
杨超越luckly2 天前
HTML应用指南:利用GET请求获取全国奈雪的茶门店位置信息
大数据·前端·python·arcgis·信息可视化·html
zhou_x_b3 天前
解决栅格数据裁剪矢量数据问题两种方法,ArcGIS解决与PYTHON解决
arcgis
维维180-3121-14553 天前
ArcGIS水文及空间分析与SWMM融合协同在城市排水防涝领域中的应用
arcgis·水文·内涝
GIS小小研究僧7 天前
ArcGIS Pro+PS 实现地形渲染效果图
arcgis·gis·qgis·地理信息
杨超越luckly7 天前
Python应用指南:使用PyKrige包实现ArcGIS的克里金插值法
python·算法·arcgis·信息可视化·克里金法
WangYan20228 天前
Python+ArcGIS+AI蒸散发与GPP估算|Penman-Monteith模型|FLUXNET数据处理|多源产品融合|专业科研绘图与可视化等
arcgis·蒸散发·光合作用·植被生产力估算
清纯世纪9 天前
Arcgis 10.7 矢量的分区统计
arcgis
猫头虎9 天前
什么是 npm、Yarn、pnpm? 有什么区别? 分别适应什么场景?
前端·python·scrapy·arcgis·npm·beautifulsoup·pip
杨超越luckly10 天前
ArcGISPro应用指南:使用ArcGIS Pro创建与优化H3六边形网格
arcgis·信息可视化·数据可视化·shp·h3网格
柳晓黑胡椒10 天前
Cesium源码打包
arcgis