Posts

Showing posts with the label xaml

WPF UserControl DependencyProperty use in XAML or by binding

Image
WPF UserControl DependencyProperty use in XAML or by binding I want a universal UserControl where i can set a property either by setting its value in XAML directly or by binding it to some model property. Just like TextBlock Text property works. Right now i just have the bare simple UserControl, it has a single DependencyProperty TxT and a TextBlock Text property bound to it. No other code present. If i set TxT in XAML on main window it wont work, binding works. If i add PropertyChangedCallback to that DependencyProperty it works also in XAML. So the question, is it mandatory to have PropertyChangedCallback for each property if i want to be able to set it directly in XAML? This is not clear to me, most don't mention about it, but it also forces me to adding internal control names to change their value in PropertyChangedCallback. The code is below. Can it be done some other way? MainWindow <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...