我有一个在代码中看起来像这样的用户控件:
using System;
using System.Windows;
using System.Windows.Controls;
namespace Client
{
public partial class Spectrum : UserControl
{
public string AntennaName { get; set; }
public Spectrum()
{
InitializeComponent();
}
}
}
和xaml(不是全部,而是重要部分):
<UserControl x:Class="Client.Spectrum"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Client"
mc:Ignorable="d" d:DesignHeight="150" d:DesignWidth="350"
Background="#253121" BorderBrush="Black" BorderThickness="1"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<StackPanel
<TextBlock Margin="10,3,0,0" Foreground="White"
FontWeight="Bold" FontStyle="Italic" TextAlignment="Left"
Text="{Binding AntennaName}"/>
</StackPanel>
</UserControl>
如您所见,我试图将 AntennaName 属性绑定到 TextBlock.Text 属性,但运气不佳。你能告诉我我做错了什么吗?