UWP win10 app 新关键字x:Bing

181 篇文章 4 订阅
128 篇文章 1 订阅

原本使用MVVM开发,我们使用数据绑定是x:Binging
新的关键字x:Bing使用和原来x:Binging区别不大。

<TextBox x:Name="textBox" TextWrapping="Wrap" Text="{x:Bind view.Text, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />

几乎没有什么改变

x:Bing的优点是

  • 速度比x:Binging快
  • 强类型
  • 可以在编译找出类型不同的错误

绑定ViewModel

直接在MainPage.xaml.cs写入viewModel view=new viewModel();
在xaml

<Page
    x:Class="uwp15.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:uwp15"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">      
        <TextBox x:Name="textBox" TextWrapping="Wrap" Text="{x:Bind view.Text, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />              
    </Grid>
</Page>

绑定方法

可以在ViewModel写一个方法,然后绑定到xaml
我们可以把常用通知属性写成一个类,给ViewModel继承
把常用通知属性写成一个类

using System.ComponentModel;

namespace ViewModel
{
    /// <summary>
    /// 提供继承通知UI改变值
    /// </summary>
    public class notify_property : INotifyPropertyChanged
    {
        public notify_property()
        {

        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this , new PropertyChangedEventArgs(name));
            }
        }
    }
}

ViewModel
ViewModel有Text Click
PointerEntered方法,给Button绑定

xaml

<Page
    x:Class="uwp15.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:uwp15"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">      
        <TextBox x:Name="textBox" TextWrapping="Wrap" Text="{x:Bind view.Text, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="258,162,302,166" />
        <Button x:Name="button" Content="{x:Bind view.Text_String_Builder}" HorizontalAlignment="Left" Margin="453,318,0,0" VerticalAlignment="Top"  Click="{x:Bind view.Click}" />
    </Grid>
</Page>

在button的PointerEntered写{x:Bind view.Click}
点击成功到view.Click断点
成功到view.Click断点

参考:http://www.cnblogs.com/tcjiaan/tag/Win10/

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值