wasm中的双向绑定

时间:2019-10-27 16:11:18

标签: uno-platform

我正在测试Uno平台和wasm。

我登录Webapi后,测试了一个简单的数据绑定,其中在文本框中有一个用户名,我更新了用户名的属性,以从viewmodel中的绑定属性测试gui的更新。

xaml。

在登录按钮中

        var result = await webApiClient.LoginUser(ViewModel.LoginModel);
        ViewModel.LoginModel.Email = result.Model.Name;

如果我在UWP下运行该应用程序,则该应用程序有效,在wasm下,该文本框不会更新。

<Page
x:Class="DeviceExchange.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DeviceExchange"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ios="http://nventive.com/ios"
xmlns:wasm="http://nventive.com/wasm"
mc:Ignorable="d ios wasm">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="1" Grid.Column="1" Text="Device Exchange 
 Portal" Margin="20" FontSize="30" />
     <TextBlock Grid.Row="2" Grid.Column="1" Text="username" Margin="3" 
 FontSize="15" />
     <TextBox Grid.Row="3" Grid.Column="1" Text="{x:Bind LoginModel.Email, 
 Mode=TwoWay}" Background="White" />
     <TextBlock Grid.Row="4" Grid.Column="1" Text="username" Margin="3" 
 FontSize="15" />
     <PasswordBox Grid.Row="5" Grid.Column="1" Password="{x:Bind 
LoginModel.Password, Mode=TwoWay}" Background="White"/>
     <Button Margin="0,5" Click="LoginButton_Click" 
VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Row="6" 
Grid.Column="1" x:Name="LoginButton" Content="Login" />
 </Grid>
 </Page>

1 个答案:

答案 0 :(得分:0)

Uno目前不支持

{x:Bind Mode=TwoWay}https://github.com/unoplatform/uno/issues/2587

相反,您可以这样写,作为一种变通方法:

Text="{Binding LoginModel.Email, Mode=TwoWay, RelativeSource={RelativeSource Self}}"