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
2009-09-07 10:43:05
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
2009-09-07 10:58:41
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
2009-09-07 11:50:54
Both controls lies in a top control that is the main window of the entire application. Is it possible to use that?
MemoryToLow
2009-09-07 12:25:53
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
2009-09-07 12:44:50
I'll try to figure that out abd test it
MemoryToLow
2009-09-07 12:49:06
Nope, can't even get this to work :(
MemoryToLow
2009-09-09 18:49:34
post some code.
ema
2009-09-10 12:59:57