我对Angular 2很新,所以请耐心等待.我试图让一个新组件出现在index.html页面中.文件集来自GitHub的基本快速启动文件.我创建了一个新组件:
import { Component } from '@angular/core';
@Component({
selector: 'app-user-item',
template: `<h1>It works!</h1>`,
})
export class UserItemComponent {
}
Run Code Online (Sandbox Code Playgroud)
我已经在HTML中声明了选择器标签:
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<base href="/">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('main.js').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
<app-user-item>loading another component</app-user-item>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我甚至尝试将导入到app.module.ts和组件名称的顶部添加到app.module.ts中的声明数组.但仍然没有.我检查了我的文件结构,并有一个js版本的user-item.component.ts.但我看不出变化.
任何帮助,将不胜感激.
干杯
我试图阻止我的应用程序的用户按下硬件后退按钮。我在 xaml 文件后面的代码中找到了这个代码片段:
protected override bool OnBackButtonPressed()
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这种方法的变体,包括使用 Boolean 而不是 Bool 并且不返回base.functionname任何内容似乎会触发此方法。这是更大的背景:
后面的代码:
namespace Watson.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class StartScan : ContentPage
{
public StartScan()
{
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈中的第二页,禁用按钮只需要在此页面上发生,其他地方不需要。
任何帮助,将不胜感激。
我已经在我的应用程序上实现了推送通知,它们工作正常。我的问题是,当我在下拉菜单中单击它们时,它们会立即重新加载该应用程序。为了解决这个问题,我让应用程序创建了一个新的活动实例。现在,这将打开一个新页面,但是当从该新页面单击返回时,它具有相同的问题并再次重新加载整个应用程序。
我将Xamarin Forms与PCL一起使用,因此它不是纯粹的Android。有没有一种方法可以使菜单项上的click事件加载到PCL中的特定页面视图?重新加载整个应用程序是没有用的。
这是创建电话通知的类:
ForegroundMessages.cs:
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class ForegroundMessages: FirebaseMessagingService
{
const string TAG = "MyFirebaseMsgService";
public override void OnMessageReceived(RemoteMessage message)
{
//Log.Debug(TAG, "From: " + message.From);
//Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
base.OnMessageReceived(message);
SendNotification(message.GetNotification().Body);
}
private void SendNotification(string body)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
// var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
Log.Debug(TAG, "Notification Message Body: " + body);
// sends notification to view model
MessagingCenter.Send((App)Xamarin.Forms.Application.Current, "Increase");
Intent resultintent = new …Run Code Online (Sandbox Code Playgroud) 我试图将参数从一个页面传递到另一个页面。这些传递的参数将用于从 SQL 表中进行选择。页面构建如下:(后面的代码)
private MainRoutePageViewModel mainroutepageviewmodel;
private List<RouteInfo> routeinfo;
Run Code Online (Sandbox Code Playgroud)
构造函数:
public MainRoutePageViewDetail(MessagDatabase database)
{
InitializeComponent();
BindingContext = mainroutepageviewmodel = new MainRoutePageViewModel(database,Navigation);
//_listOfProperties = mainroutepageviewmodel.GetLabelInfo();
ScrollView scrollview = new ScrollView();
StackLayout mainstack = new StackLayout();
mainstack.Spacing = 0;
mainstack.Padding = 0;
//mainstack.HeightRequest = 2000;
routeinfo = mainroutepageviewmodel.GetLabelInfo();
string _routePlacer = "";
foreach (var i in routeinfo)
{
mainstack.Children.Add(NewRouteName(i.RouteName));
mainstack.Children.Add(BuildNewRoute(i.RouteStops,i));
_routePlacer = i.RouteName;
}
scrollview.Content = mainstack;
Content = scrollview;
}// end of constructor
Run Code Online (Sandbox Code Playgroud)
BuildNewRoute 方法:
public StackLayout BuildNewRoute(List<string> location, RouteInfo routeinfo) …Run Code Online (Sandbox Code Playgroud) 我正在使用Xaml为UI处理Xamarin表单项目的数据绑定.到目前为止它非常简单:
XAML:
<?xml version="1.0" encoding="utf-8" ?>
Run Code Online (Sandbox Code Playgroud)
xmlns:viewModels="clr-namespace:Watson.ViewModels;assembly=Watson"
x:Class="Watson.Views.DeviceCheck">
<ContentPage.BindingContext>
<viewModels:DeviceCheckViewModel/>
</ContentPage.BindingContext>
<!--<ActivityIndicator Color="Red" IsRunning="True"
x:Name="loadingScreen"/>-->
<StackLayout>
<Label Text="Checking Device.."/>
<Button Text="page nav"
Command="{Binding NextButton}"></Button>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
背后的代码:
namespace Watson.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DeviceCheck:ContentPage
{
private DeviceCheckViewModel viewModel;
public DeviceCheck() {
InitializeComponent();
BindingContext = viewModel = new DeviceCheckViewModel(this.Navigation);
}// end of constructor
}// end of class
}// end of namespace
Run Code Online (Sandbox Code Playgroud)
这是尝试绑定到视图模型并使用绑定命令在按钮单击时转到另一个页面.我得到的错误是"给定的密钥不在字典中",这是在尝试构建时.我把问题隔离到了这一行:<viewModels:DeviceCheckViewModel/>
我不知道为什么会出现这种错误.
这是视图模型:
namespace Watson.ViewModels
{
public class DeviceCheckViewModel: INotifyPropertyChanged
{
public INavigation Navigation { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Xamarin表单在Web视图中加载本地HTML页面。我可以在开发文档中使用基本示例,尽管可以加载URL,但无法加载自己的HTML页面。这仅需要通过Android完成,因此无需担心IOS和Windows。
Xaml:
<WebView
x:Name="webviewjava"></WebView>
Run Code Online (Sandbox Code Playgroud)
后面的代码:
public partial class javscriptExample : ContentPage
{
public interface IBaseUrl { string Get(); }
public javscriptExample()
{
InitializeComponent();
var source = new HtmlWebViewSource();
source.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
webviewjava.Source = source;
}
}
Run Code Online (Sandbox Code Playgroud)
平台特定文件(LocalFile.cs):请注意,此文件已被设置为Android资源。
[assembly: Dependency(typeof(LocalFiles))]
namespace maptesting.Droid
{
public class LocalFiles: IBaseUrl
{
public string Get()
{
return "file:///android_asset/";
}
}
}
Run Code Online (Sandbox Code Playgroud)
在资产文件夹下有一个“ TestWebPage.html”,也已设置为Android资产。
尽管我不知道问题出在哪里,但我已通过调试将其放置,并且基本URL重新变空。为了清楚起见,我没有找到文件,屏幕只是空白。另外,我不确定这是否有所作为。LocalFiles.cs文件中的“ IBaseUrl”上没有突出显示语法。因此,我不确定它是否可以“看到”它。
有任何想法吗?
我似乎无法得到这个问题的直接答案。我试图在后面的代码中设置项目源。这在 Xaml 中很容易做到,但在后面的代码中似乎并不那么简单。
在我使用的后面的代码中:
Binding listbind = new Binding("routeLabels") {Source=this};
listviewofroutes.ItemsSource = SetBinding(ListView.ItemsSourceProperty, listbind);
Run Code Online (Sandbox Code Playgroud)
这只会引发“无法将 void 转换为 System.Collections.IEnumerable”的错误,我也认为这不正确。
我试图将它绑定到视图模型中的可观察集合。
视图模型:
private ObservableCollection<RouteInfo> _routelabels;
public ObservableCollection<RouteInfo> routeLabels
{
get { return _routelabels; }
set
{
if (Equals(value, _routelabels)) return;
_routelabels = value;
OnPropertyChanged(nameof(routeLabels));
}
}
Run Code Online (Sandbox Code Playgroud)
在 Xaml 中设置绑定时,此绑定工作正常。问题不是可观察的集合问题是我不知道如何在后面的代码中设置绑定。
概括:
我需要知道如何做到这一点(itemsource 绑定):
<ListView x:Name="listviewofroutes" ItemsSource="{Binding routeLabels}">
</ListView>
Run Code Online (Sandbox Code Playgroud)
在后面的代码中。
任何帮助,将不胜感激。
我在连续两次选择列表视图项目时遇到问题。因此,当我选择一个项目时,它会加载另一个列表。这不是问题,但是当我单击返回以返回上一个列表视图时,我无法再单击相同的列表视图项。我已经阅读了一些内容,似乎有一种想法可以在代码中的某个点“取消选择”列表视图项,以便能够再次选择相同的项。选择是使用 MVVM 模型完成的,因此处理选择的代码等。
// bound to list items on front end, reacts to tap on each item
// and loads route information for the route that is selected
RouteInfo _selected_item;
public RouteInfo RouteLabelSelected
{
get { return _selected_item; }
set
{
if (Equals(value, _selected_item)) return;
_selected_item = value;
OnPropertyChanged(nameof(RouteLabelSelected));
OpenRoutePage(_selected_item.ID);
}
}
Run Code Online (Sandbox Code Playgroud)
OpenRoutePage 方法只是打开下一个列表视图,正如我所说的那样工作正常。我附上了一些图片以更好地说明问题。
任何帮助将不胜感激,请原谅艺术品。
我遇到了最简单的代码问题,我确定它的东西很愚蠢.当我把';' 在主要功能之后,它说出了旧式格式化列表的内容.所以,当我删除它时,它说有一个';' 在')之前失踪.任何帮助将不胜感激,代码如下:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
int i;
for (i = 0, i < 10, i++)
cout << i << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
顺便说一下,这一切都在视觉工作室表达中,对于for循环而言,放置{}对结果没有任何影响.
我在点击列表视图中的项目后尝试打开另一个视图.我尝试过添加一个TapGestureRegonizer甚至添加ViewCell网格等等.这些似乎都不起作用.我已经为标签添加了一个轻击手势,这似乎有效,但同样不适用于列表视图项目.这似乎是列表视图之类的简单问题,但似乎没有内置的功能.
Xaml:
<ListView x:Name="dataList"
ItemsSource="{Binding routeLabels}"
HasUnevenRows="True"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3">
</ListView>
Run Code Online (Sandbox Code Playgroud)
背后的代码:
var listviewgesture = new TapGestureRecognizer();
listviewgesture.SetBinding(TapGestureRecognizer.CommandProperty,"LoadRoutePage");
dataList.GestureRecognizers.Add(listviewgesture);
Run Code Online (Sandbox Code Playgroud)
视图模型:
public ICommand LoadRoutePage { get; protected set; }
public DriverDashboardViewModel(INavigation navigation,MessagDatabase database)
{
this._database = database;
this.Navigation = navigation;
this.LoadNotifications = new Command(async () => await OpenNotificationsPage());
this.LoadRoutePage = new Command(async () => await OpenRoutePage());
}
public async Task OpenRoutePage()
{
await Navigation.PushAsync(new RoutePageView());
}
Run Code Online (Sandbox Code Playgroud)
要明确的是,该LoadNotifications方法确实可以打开页面,但却LoadRoutePage没有.所以我知道视图和视图模型之间存在某种程度的通信.