tags:

views:

87

answers:

1

In one UserControl I have option buttons that are supposed to change the visibility of rectangles in another user control and I can't find out how to do this. Can anyone give me some code example for this?

+1  A: 

The user control should raise an event that the second control use to change the visibility:

//FirstControl
public event EventHandler SelectionChanged;
private void OnOptionButtonSelectionChange(....)
{
  if (SelectionChanged != null)
    SelectionChanged(this, EventArgs.Empty);
}

//SecondControl
public void Setup()
{
  firstControlInstance.SelectionChanged += new EventHandler(manage_SelectionChanged);
}

private void manage_SelectionChanged(Object sender, EventArgs e)
{

}

Alternatively,if the controls are decoupled you could use a Mediator like this: http://sachabarber.net/?p=477

ema
I'm very new to XAML and WPF so my follow up question is, how do a create 'firstControlInstance' When I just try to use the 2nd controls name, I don't see the 'SelectionChanged'. Also the 'public event EventHandler SelectionChanged' don't give me the last word(SelectionChanged' the light blue color, it's just black like normal variables
MemoryToLow
if you decide to use the events the two instances (firstControl and secondControl) must be managed by a mediator that has the instances of two controls. But if the secondControl is defined "inside" the firstControl it's much simpler: secondConltrol is just an instance variable.For the event remember that you can define your own event with the necessary parameters, so SelectionChanged can pass all the informarion needed to your application.
ema
Both controls lies in a top control that is the main window of the entire application. Is it possible to use that?
MemoryToLow
Sure! the first control fire the event when the selection change, the top control (the container) intercept the event and calls a method on the second control to propagate the changes.
ema
I'll try to figure that out abd test it
MemoryToLow
Nope, can't even get this to work :(
MemoryToLow
post some code.
ema