如何解决如何在不同的 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 文件中的地图。 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; }
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。