I did tried it following way but still not able to make it work:
page.xaml:
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<TextBox x:Name="TextDataCollectionAccounts" Width="200" Height="25" VerticalAlignment="Top"></TextBox>
<ToggleButton x:Name="ButtonShowHideCalander" Content="Date" IsThreeState="False" Width="100" Click="ToggleButton_Click" Height="25" VerticalAlignment="Top"></ToggleButton>
<Local:MyUserControl x:Name="RCalanderData" DateRange="{Binding ElementName=TextDataCollectionAccounts, Path=Text, Mode=TwoWay}" Visibility="Collapsed"/>
page.xaml.cs
private MyUserControl uc=new Rlight.Views.ExportImport.Controls.MyUserControl();
public page()
{
InitializeComponent();
uc.OkButton.Click+=new RoutedEventHandler(Button_Click_control);
}
private void Button_Click_control(object sender, RoutedEventArgs e)
{
TextDataCollectionAccounts.Text = uc.DateDatas;
}
MyUserControl.xaml
<TextBox x:Name="ResultSelectedDates" Grid.Row="1" Text="{Binding DateRange, Mode=TwoWay}" Width="100"/><Button x:Name="OkButton" Content="Ok" Height="40" Width="102"></Button>
MyUserControl.xaml.cs
public partial class MyUserControl : UserControl
{
public static readonly DependencyProperty DateRangeProperty =
DependencyProperty.Register("DateRange", typeof(String), typeof(MyUserControl), new PropertyMetadata(DataRangeChanged));
public MyUserControl()
{
InitializeComponent();
this.DataContext = new AccountingViewModel();
}
public string DateRange
{
get
{
return (string)GetValue(DateRangeProperty);
}
set
{
SetValue(DateRangeProperty, value);
}
}
private static void DataRangeChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
MyUserControl item = (source as MyUserControl);
if (item != null) item.ResultSelectedDates.Text = e.NewValue.ToString();
}
}