i have a usercontrol that looks like this in code:
using System;
using System.Windows;
using System.Windows.Controls;
namespace Client
{
public partial class Spectrum : UserControl
{
public string AntennaName { get; set; }
public Spectrum()
{
InitializeComponent();
}
}
}
and the xaml ( not in whole but the important parts ):
<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>
as you can see im trying to bind the AntennaName property to the TextBlock.Text property but without much luck.
can you tell me what am i doing wrong?
You don’t have any way of notifying the binding system when the property changes.
You should create a dependency property, which will automatically use the existing notification system in WPF.
To do that, type
propdpand press Tab to activate Visual Studio’s built-in code snippet.Alternatively, create a separate ViewModel class and implement INotifyPropertyChanged.