gpt4 book ai didi

c# - 系统.Windows.数据错误 : 4 : Cannot find source for binding with reference

转载 作者:太空宇宙 更新时间:2023-11-03 16:07:34 27 4
gpt4 key购买 nike

我在一个 VS 2012 解决方案中有 3 个项目。下面是在项目 A 中抛出此错误的 XAML 文件。 BmpImage.cs 文件存在于同一解决方案中的不同项目 B 中,其中包含所有扩展和帮助文件,并包含所有方法和代码这是必需的。项目 A 引用项目 B。

有人可以帮忙吗?我的工作在这里,但我被困住了。我已经阅读了所有其他类似的问题,但没有一个能解决这个问题。

我收到这个错误:

System.Windows.Data Error: 4 : Cannot find source for binding withreference 'RelativeSource FindAncestor,AncestorType='System.Windows.Controls.Button', AncestorLevel='1''.BindingExpression:Path=IsEnabled; DataItem=null; target element is'BmpImage' (Name=''); target property is 'NoTarget' (type 'Object')

<UserControl x:Class="MyGrid.MyPanel" 
Name="_ctrl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ex="clr-namespace:Helper.Xaml;assembly=Helper.Xaml"
xmlns:sx="clr-namespace:MyPanel.Xaml;assembly=MyPanel.Xaml">
<UserControl.Resources>
**<Style x:Key="BmpStyle" TargetType="{x:Type ex:BmpImage}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
<Setter Property="UIElement.Opacity" Value="0.3" />
</DataTrigger>
</Style.Triggers>
</Style>**
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ToolBar ToolBarTray.IsLocked="True">
<Button ToolTip="Filter..." ToolTipService.ShowOnDisabled="True" Click="Filter_OnClick">
<ex:BmpImage Source="Images/filter.png" Style="{StaticResource BmpStyle}" />
</Button>
<ToggleButton ToolTip="AutoScroll" ToolTipService.ShowOnDisabled="True" IsChecked="{Binding ElementName=Trades, Path=AutoScroll}">
<ex:BmpImage Source="Images/Autoscroll.png" Style="{StaticResource BmpStyle}" />
</ToggleButton>
</ToolBar>
<sx:PanelGrid Name="PanelGrid" Grid.Row="1" />
</Grid>
</UserControl>

最佳答案

您的代码看起来是正确的...您是否尝试过不使用可选的 AncestorLevel=1Binding 表达式?我通常使用这种 Binding,但我从不理会 AncestorLevel 属性,因为如果设置错误,它可能会导致错误,或者如果 XAML 发生过更改。

<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
Button}}, Path=IsEnabled}" Value="False">
<Setter Property="UIElement.Opacity" Value="0.3" />
</DataTrigger>

关于c# - 系统.Windows.数据错误 : 4 : Cannot find source for binding with reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com