绑定到相对来源中的 属性 将我发送到主窗口 + Catel
Bind to property in a relative source sends me up to the mainwindow + Catel
有以下xaml代码
<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>
当我尝试绑定内部视图的可见性 属性 时
<Views:dataProducto_CategoriasView DataContext="{Binding SelectedProducto_Categoria}" Visibility="{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.VistaDetalleEsVisible, Converter={StaticResource booleanToVisibilityConverter}}" />
它向父级发送我一直到主 window 的数据上下文。
父项加载到主 window 内的 contentControl 中。
为什么我不能绑定到父用户控件的数据上下文?
和完全一样的问题。
阅读文档,特别是文章 UserControl - Under the hood。
有以下xaml代码
<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>
当我尝试绑定内部视图的可见性 属性 时
<Views:dataProducto_CategoriasView DataContext="{Binding SelectedProducto_Categoria}" Visibility="{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.VistaDetalleEsVisible, Converter={StaticResource booleanToVisibilityConverter}}" />
它向父级发送我一直到主 window 的数据上下文。
父项加载到主 window 内的 contentControl 中。
为什么我不能绑定到父用户控件的数据上下文?
和
阅读文档,特别是文章 UserControl - Under the hood。