zoukankan      html  css  js  c++  java
  • 【WPF学习日记】——Window的DataContext绑定ViewModel

    1、全局的ViewModel绑定:

        a)设定全局的ViewModel(App.xaml中): 

    1 <Application x:Class="MyTest.App"
    2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4         xmlns:local="clr-namespace:MyTest"
    5         StartupUri="MainWindow.xaml">
    6     <Application.Resources>
    7     <local:MainViewModel x:Key="mainVM"/>
    8     </Application.Resources>
    9 </Application>

         b)绑定全局的ViewModel(MainWindow中):  

    1 <Window x:Class="MyTest.MainWindow"
    2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4 xmlns:local="clr-namespace:MyTest"
    5 Title="MainWindow" Height="600" Width="850" WindowStartupLocation="CenterScreen"
    6 DataContext="{DynamicResource mainVM}">
    7 </Window>

    2、单独的ViewModel绑定(MainWindow中):

    1 <Window x:Class="MyTest.MainWindow"
    2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4         xmlns:local="clr-namespace:MyTest"
    5         Title="MainWindow" Height="600" Width="850" WindowStartupLocation="CenterScreen">
    6     <Window.DataContext>
    7         <local:MainViewModel/>
    8     </Window.DataContext>
    9 </Window>
    一点一滴,记录
  • 相关阅读:
    Rust 常见集合
    Rust模块
    Rust包和crate以及模块
    Rust枚举和模式匹配
    React Native滚动到指定位置
    三行代码让你的React/RN应用动起来
    React Native添加自定义全局组件
    MAC下网易MuMu模拟器调试ReactNative
    解决React Navigation goBack()无效
    “Mac应用”已损坏,打不开解决办法
  • 原文地址:https://www.cnblogs.com/zuixieyang/p/3865678.html
Copyright © 2011-2022 走看看