First, I have three links for you and I really hope for your sake, that you read the linked pages. The first link from MSDN should help you to get started with WPF as it's clear that you have no idea how to use it yet:
The second and third links are from the StackOverflow Help Center because it's also clear that you haven't read these pages either and they will help you to get the most out of this website (and get your questions answered quicker):
How do I ask a good question?
How to create a Minimal, Complete, Tested and Readable example
Now to address your question... you can simply add a DependencyProperty
to your UserControl
and data bind to it from both inside and outside the control. In code behind:
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(string), typeof(MainWindow), new UIPropertyMetadata("Some text"));
public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
The XAML inside UserControl
:
<TextBlock Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type
YourLocalPrefix:YourControlname}}}" />
The XAML outside UserControl
:
<YourLocalPrefix:YourControlname Value="{Binding SomePropertyOutsideControl}}}" />