I'm trying to understund how datacontex is passed to usercontrols.
I have 2 classes:
public class OuterClass
{
public InnerClass inner {get; set;}
}
public class InnerClass
{
public void targetFun()
{
//do something
}
}
And the Main Window class
public class MainWindow: Window
{
public OuterClass outer {get; set;}
//...
}
In the main window xaml file the DataContext is set to be the Outer class
<Window <!-- Properties --> >
<Grid DataContext="{Binding outer}">
<MyControl DataContext="{Binding inner}">
<!-- Here I do more stuff from outer class -->
</Grid>
</Window>
And this would be the definition of my UserControl
<UserControl x:Class="my:MyControl">
<Grid>
<TextBlock MouseDown="targetFun">Click me!</TextBlock>
</Grid>
</UserControl>
When I try to compile I get the error that the function "targetFun" does not exist in 'MyControl' it means that the compiler does not realize im trying to set the context in inner. How do I do that.
Sorry for the simple code I can't show the real one but this is pretty much what i'm doing. Thanks!
Edit: Typo