c# - 如何在不同的 xaml 文件中访问 xaml 属性
问题描述
我有 2 个两个不同的 xaml 文件,例如 about 和 addgeojson。第一个(大约)是:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="myMapApp.Views.AboutPage"
xmlns:vm="clr-namespace:myMapApp.ViewModels" xmlns:local="clr-namespace:Naxam.Controls.Forms;assembly=Naxam.Mapbox.Forms"
Title="{Binding Title}">
<ContentPage.BindingContext>
<vm:AboutViewModel />
</ContentPage.BindingContext>
<StackLayout>
<local:MapView
x:Name="map"
x:FieldModifier="Public"
VerticalOptions="FillAndExpand"
MapStyle="mapbox://styles/mapbox/satellite-v9"
ZoomLevel="3"
/>
</StackLayout>
</ContentPage>
我想访问 x:Name 是 addgeojson xaml 文件中的映射的 mapview 对象。about.map 不起作用。如何访问地图属性?我需要在其他文件中使用 map.functions。
- 更新 -
现在,我创建了一个视图模型。我使用了一个实例来获取地图的值。我可以从任何地方访问中心、缩放和属性。此外,“customMap2”实际上具有 Functions 属性。但是,除了程序的开头之外,它返回 null。因此,我不能从其他文件中使用这些地图功能。我希望该用户从移动设备中选择一个 geojson 文件并加载到地图。怎么了?
using Naxam.Controls.Forms;
using Naxam.Mapbox;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace myMapApp.ViewModels
{
public class mapPage
{
private static mapPage _instance = new mapPage();
public static mapPage Instance { get { return _instance; } }
public MapView customMap2 = new MapView
{
MapStyle = MapStyle.SATELITE,
VerticalOptions = LayoutOptions.FillAndExpand,
ZoomLevel = 3,
Functions = MapFunc
};
private static IMapFunctions MapFunc { get; set; }
public IMapFunctions GetFunc
{
get { return MapFunc; }
set { return; }
}
}
}
解决方案
推荐阅读
- react-native - 状态更改时 React-Native-Component 不呈现
- java - 使用 Runtime.getRuntime().exec 执行 cmd 时如何隐藏 cmd 窗口
- php - 在 CENTOS 下运行 CRON JOBS
- angular - Angular - 多个订阅序列不起作用
- flutter - Flutter Navigation Drawer ExpansionTile 在下一个选项被选中时不会折叠以前打开的选项
- .net - 使用 C# 提取 7z SFX 文件
- python - 存储在 Python 方法中定义的数据帧和变量
- sapui5 - 调整页面大小时重命名列标题
- r - How to create multiple dataframes with lapply()?
- javascript - 如何从外部文件访问反应组件