wpf 的binding 方式

参考:WPF中的Binding的常见知识点与技巧_哔哩哔哩_bilibili

总结了一些:wpf中的binding的方式。

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontSize="20"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfBindingDemo"
        mc:Ignorable="d"
        x:Name="myWindow"
        Title="MainWindow" Height="1050" Width="800">
   
       
       
   

   
        测试数据
       
   

   
       
           
           
           
           
           
           
           
           
           
           
               
                   
               

           

           
               
                   
               

           

           
           
               
                   
                   
                   
                   
               

           

           
           
           
               
                   
                       
                       
                   

               

           

           
           
               
               
               
           

           
           
           
       

        
   

类文件

namespace WpfBindingDemo
{
    ///


    /// Interaction logic for MainWindow.xaml
    ///

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Resources["test"] = DateTime.Now.ToString();
        }
    }
    class MyResource
    {
        public string Message { get; set; } = "test 哈哈";
        public static string StaticString = "static string";
        public const string ConstString = "Const string";
    }
    public enum MyEnum
    {
        Message,
        OK,
        Error
    }

MainViewModel.cs

namespace WpfBindingDemo
{
    public  class MainViewModel
    {
        public string Name { get; set; }
        public string Message { get; set; } = "test 哈哈";
        public string MessageKong { get; set; }
    }
}

你可能感兴趣的:(wpf,ui)