Raising an event when the content of an user control change
.net, c#, multithreading, user-interface, wpf
Solution
In WPF you can set to raise event for any `DependencyProperty` so if you would like to raise event on `Content` change
var desc = DependencyPropertyDescriptor.FromProperty(ContentControl.ContentProperty, typeof(UserControl));
desc.AddValueChanged(container, ContentPropertyChanged);
and do what you need in here:
private void ContentPropertyChanged(object sneder, EventArgs e)
{
//event handler
}
Problem
I have a WPF application in which i have this user control View ``` <Grid Background="{StaticResource ResourceKey=baground}" > <DockPanel > <UserControl x:Name="container" ></UserControl> </DockPanel> </Grid> ``` I need to add an event that is raised when the content of `container` change : ``` private void container_LayoutUpdated_1(object sender, EventArgs e) { Thread windowThread2 = new Thread(delegate() { verifing2(); }); windowThread2.SetApartmentState(ApartmentState.STA); windowThread2.IsBackground = true; windowThread2.Start(); Thread windowThread3 = new Thread(delegate() { verifing3(); }); windowThread3.SetApartmentState(ApartmentState.STA); windowThread3.IsBackground = true; windowThread3.Start(); } ``` As you can see , i tried the event `LayoutUpdated` but it is not the best idea, i think, because it is raised many times even the `container`'s content is not changed. - How can i resolve this? Thanks,