ca Thich

ca Thich

  • 1.7k
  • 48
  • 565

How to Binding data to User Control loaded in Control Template?

Apr 22 2022 5:21 PM

Hi,

My CMainViewModel has a property called AnalogGaugeValue1

On my main Windows I have a data template as shown below.  I use this template to load a user control name AnalogIOView and try to binding the dependecy property, GaugeValue1DP, inside AnalogIOView to the AnalogGaugeValue1

GaugeValue1DP="{Binding Path=AnalogGaugeValue1}"   />

I use the ContentControl to load the AnalogIOViewTemplate as shown below

The user control displays correctly on my Window but I could not set the Analog Gauge value through binding in CMainViewModel.

However, If I just load the user control directly (without using Control Template) then it is working correctly as shown below

GaugeValue1DP="{Binding Path=AnalogGaugeValue1}"   />

My question is why it does not work when loading the user control using Content control and data template

Thanks for your help