namespace MyClassLibrary
{
public class MyClass
{
public string MyName { get; set; }
}
}
在UI工程添加自定义库的引用
在XMAL中创建资源,并与UI控件绑定
<Window x:Class="MyLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myclass="clr-namespace:MyClassLibrary;assembly=MyClassLibrary"
Title="MainWindow" Height="100" Width="200">
<Window.Resources>
<myclass:MyClass x:Key="myClass" MyName="Kyran"/>
</Window.Resources>
<Grid>
<TextBox Text="{Binding Source={StaticResource myClass}, Path=MyName}"/>
</Grid>
</Window>