1

Have the following xaml code

<catel:UserControl x:Class="SICUAP.Views.CatProducto_CategoriasView"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:catel="http://catel.codeplex.com"
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                   xmlns:Views="clr-namespace:SICUAP.Views">

    <!-- Resources -->
    <UserControl.Resources>        
    </UserControl.Resources>

    <!-- Content -->
    <catel:StackGrid>
        <catel:StackGrid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </catel:StackGrid.RowDefinitions>
        <Views:cmdGlobalesBDView></Views:cmdGlobalesBDView>
        <Label Content="Catalogo de Categorias de Producto" Style="{StaticResource estiloTituloControl}">
        </Label>
        <DataGrid Margin="0 10 0 0" MaxHeight="200" ItemsSource="{Binding Producto_Categorias}" SelectedItem="{Binding SelectedProducto_Categoria}" AutoGenerateColumns="False" 
                      ScrollViewer.VerticalScrollBarVisibility="Auto" CanUserAddRows="False" CanUserResizeColumns="False" AlternatingRowBackground="#D2EDF7">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="CLAVE" MinWidth="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding ID_CATEGORIA}"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="NOMBRE" MinWidth="200">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding NOMBRE}"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="DESCRIPCION" MinWidth="300">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding DESCR}" HorizontalAlignment="Stretch"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>            
            <DataGrid.CellStyle>
                <Style TargetType="{x:Type DataGridCell}">
                    <Style.Triggers>
                        <Trigger Property="DataGridCell.IsSelected" Value="True">
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
        </DataGrid>
        <Views:dataProducto_CategoriasView DataContext="{Binding SelectedProducto_Categoria}" Visibility="{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.VistaDetalleEsVisible, Converter={StaticResource booleanToVisibilityConverter}}" />
    </catel:StackGrid>
</catel:UserControl>

When i try to bind the Visibility property of the internal view

<Views:dataProducto_CategoriasView DataContext="{Binding SelectedProducto_Categoria}" Visibility="{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.VistaDetalleEsVisible, Converter={StaticResource booleanToVisibilityConverter}}" />

to the parent it sends me all the way up to the datacontext of the main window.

The parent is loaded in a contentControl inside the main window.

Why i cant bind to the datacontext of the parent user control?

1 Answers1

0

It's exactly the same question as this one.

Read the docs, specifically the article UserControl - Under the hood.

Community
  • 1
  • 1
Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32
  • Thanks for the work around. This did the trick. ` ` – Salvador Ruiz Guevara Jul 21 '15 at 22:32
  • 1
    And instead of binding to a DataContext, you can also bind to ViewModel: {Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=ViewModel.VistaDetalleEsVisible, Converter={StaticResource booleanToVisibilityConverter}} – Geert van Horrik Jul 22 '15 at 06:43