WPF Demo7

没有Path/Source的数据绑定

本地local资源用法

namespace Demo9
{
    public class Student
    {
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string nickName;

        public string NickName
        {
            get { return nickName; }
            set { nickName = value; }
        }
    }
}
<Window x:Class="Demo9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Demo9"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <StackPanel.DataContext>
            <local:Student Name="swg" NickName="kunkun"/>
        </StackPanel.DataContext>
        <TextBlock Text="{Binding Name}"/>
        <TextBlock Text="{Binding NickName}"/>
    </StackPanel>
</Window>

原文地址:https://www.cnblogs.com/YYkun/p/6867181.html