I’m working on a WPF custom control. The control has a property that is set in code behind and used in XAML. This property must be public for it work on XAML via a Binding. Why is this, if there is just one class?
<TextBlock Text="{Binding ElementName=PolicyBoxName, Path=FileNames[0]}" />
private string[] _fileNames;
public string[] FileNames
{
get
{
return _fileNames;
}
set
{
if (value != _fileNames)
{
_fileNames = value;
OnPropertyChanged("FileNames");
}
}
}
The XAML parsers constructs objects based on the supplied XML and sets their properties. It is no different from any other class, from a different namespace, that might wish to create your user control and set its properties. Without reflection, the constraints of the C# language demand that these properties are public for them to be set.