我创建了一个新的Xamarin.Forms移动应用程序,我唯一做的就是将'use strict';
const Web3 = require('web3');
const wsAddress = 'wss://rinkeby.infura.io/ws';
const contractJson = '(taken from solc or remix online compiler)';
const privateKey = '0xOOOX';
const contractAddress = '0xOOOX';
const walletAddress = '0xOOOX';
const webSocketProvider = new Web3.providers.WebsocketProvider(wsAddress);
const web3 = new Web3(new Web3.providers.WebsocketProvider(webSocketProvider));
const contract = new web3.eth.Contract(
JSON.parse(contractJson),
contractAddress
);
// change this to whatever contract method you are trying to call, E.G. SimpleStore("Hello World")
const query = contract.methods.SimpleStore('Hello World');
const encodedABI = query.encodeABI();
const tx = {
from: walletAddress,
to: contractAddress,
gas: 2000000,
data: encodedABI,
};
const account = web3.eth.accounts.privateKeyToAccount(privateKey);
console.log(account);
web3.eth.getBalance(walletAddress).then(console.log);
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
const tran = web3.eth
.sendSignedTransaction(signed.rawTransaction)
.on('confirmation', (confirmationNumber, receipt) => {
console.log('=> confirmation: ' + confirmationNumber);
})
.on('transactionHash', hash => {
console.log('=> hash');
console.log(hash);
})
.on('receipt', receipt => {
console.log('=> reciept');
console.log(receipt);
})
.on('error', console.error);
});
文件中的默认欢迎替换为xamarin标签:
.xaml
预览器无法在android或ios预览版上运行,当我运行程序时,我在这行代码上得到 <Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>>
<ColumnDefinition Width="*"/>>
<ColumnDefinition Width="*"/>>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Text="You are: (X)" Grid.Row="0" Grid.Column="0" Margin="5"/>
<Label Text="Your opponent is: (O)" Grid.Row="0" Grid.Column="2" Margin="5" HorizontalTextAlignment="End"/>
</Grid>
,这已经在预生成的代码中:System.InvalidCastException
< / p>
我还是初学者,所以我对此进行了一些搜索,大部分时间都是在开发人员编写的代码中抛出异常,但是在这种情况下除了删除{{1}之外我没有触及任何内容来自global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(ticTactTestPage));
文件。任何人都可以帮忙解决这个问题吗?
编辑1:用户建议移动<Label Text="Welcome to Xamarin!"/>
内的标签,因为我原来在外面使用它们。但问题仍然存在。
答案 0 :(得分:2)
您的ColumnDefinition Widths元素末尾有一个额外的>
:
<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
</Grid>
<Label Text="You are: (X)" Grid.Row="0" Grid.Column="0" Margin="5"/>
<Label Text="Your opponent is: (O)" Grid.Row="0" Grid.Column="2" Margin="5" HorizontalTextAlignment="End"/>
要在XAML中捕获大多数这些类型的拼写错误,您可以启用XAML编译器(XAMLC
)。
XAMLC提供了许多好处:
~~~~
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace PhotoApp
~~~~
[XamlCompilation (XamlCompilationOptions.Compile)]
public class HomePage : ContentPage
{
~~~