Hi,
I have a UserControl say MyDialog and it has got a property as shown below,
public static readonly DependencyProperty OpenInWordStyleProperty =
DependencyProperty.Register("OpenInWordStyle", typeof(MyDocumentExtensionType),
typeof(MyDialog), new PropertyMetadata(MyDocumentExtensionType.WordDocumentStyle, new PropertyChangedCallback(OnChanged)));
private static void OnChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MyDialog dialog = d as MyDialog ;
ViewModel.MyViewModel viewModel = dialog.DataContext as ViewModel.MyViewModel;
viewModel.SetOpenInWordToggleButtonStyle(dialog.OpenInWordStyle.ToString());
}
// Property wrapper
public MyDocumentExtensionType OpenInWordStyle
{
get
{
return (MyDocumentExtensionType)GetValue(OpenInWordStyleProperty);
}
set
{
SetValue(OpenInWordStyleProperty, value);
}
}
Now i want to set the above 'OpenInWordStyle' property from my other UserControl say 'MyParentDialog', MyParentDialog has a Listbox and its Itemtemplate is as shown below,
<ListBox.ItemTemplate><DataTemplate><Expander DataContext="{Binding}" Style="{DynamicResource MyDocExpanderStyle}" Header="{Binding DocumentName}"
IsExpanded="{Binding IsNodeExpanded, Mode=OneTime}" Expanded="myDocExpander_Expanded" ><ItemsControl ItemsSource="{Binding Files}" Background="White" ><ItemsControl.ItemTemplate><DataTemplate><Grid Margin="20,2,8,2" x:Name="DocumentNameGrid"><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions><TextBlock x:Name="DocumentNameTextBlock" Background="White" Style="{StaticResource PracticeAreasTitleStyleArial}"><Run Text="{Binding NameOfDocument, IsAsync=True}"/><Run Text="{Binding DocumentExtension}"/></TextBlock><Border Grid.Column="1" x:Name="OpenInWordBorder" Margin="2"><ContentControl DataContext="{Binding DocumentExtension}" ContentTemplate="{StaticResource MyToggleButtonTemplate}"/></Border></Grid></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></Expander></DataTemplate></ListBox.ItemTemplate>
In ContentControl's ContentTemplate i am calling 'MyDialog' usercontrol and binding the 'OpenInWordStyle' property. as shown below,
<DataTemplate x:Key="MyToggleButtonTemplate"><MyControls:MyDialog x:Name="MyDialog" OpenInWordStyle="{Binding DocumentExtension}" Grid.Column="1" Margin="2"
HorizontalAlignment="Stretch" VerticalAlignment="Center" ><MyControls:MyDialog.CommandBindings><CommandBinding Command="{x:Static MyControls:MyDialogCommands.SelectedTemplateChangeCommand}" Executed="MySelectedItemChangedCommandBinding_Executed"/><CommandBinding Command="Save" Executed="MyDialogShowCommandBinding_Executed" CanExecute="MyDialogShowCommandCanExecuteBinding_Executed" /><CommandBinding Command="{x:Static MyControls:MyDialogCommands.MoreButtonClickCommand}" Executed="MyDialogMoreButtonClickCommandBinding_Executed"/><MyControls:MyDialog.CommandBindings></MyControls:MyDialog></DataTemplate>
Please help me out how i can bind 'DocumentExtension' property of MyParentDialog to 'OpenInWordStyle' property of MyDialog.
Regards,
Chetan Rajakumar