我有这个代码示例
Class1.cs:
namespace WpfApp1
{
public class Class1
{
public string ForButton { get; set; } = "I'm button";
public string ForTextBlock { get; set; } = "Ï'm TextBlock";
}
}
MainWindow.xaml.cs:
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public Class1 test = new Class1();
public MainWindow()
{
InitializeComponent();
}
}
}
和MainWindow.xaml:
<Window x:Class="WpfApp1.MainWindow"
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"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Button Height="30"/>
<TextBlock Height="30"/>
</StackPanel>
</Window>
我想知道如何将字符串ForButton
和ForTextBlock
绑定为 Button 和 Button Text 对 TextBox 的适用性。