C# BindingExpression路径错误:未找到属性
BusyIndicator.xamlC# BindingExpression路径错误:未找到属性,c#,wpf,xaml,user-controls,C#,Wpf,Xaml,User Controls,BusyIndicator.xaml <UserControl x:Class="Eigen.Modules.Modelling.Components.BusyIndicator" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<UserControl x:Class="Eigen.Modules.Modelling.Components.BusyIndicator"
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:local="clr-namespace:Eigen.Modules.Modelling.Components"
xmlns:telerikControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d"
d:DesignHeight="150" d:DesignWidth="150"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid Width="{Binding Width}" Height="{Binding Height}">
<telerikControls:RadBusyIndicator IsIndeterminate="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=IsIndeterminate}">
<Border BorderBrush="White" Background="#A9FFFFFF" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Padding="5,0" Grid.Row="0">
<Image gif:ImageBehavior.AnimatedSource="/`enter code here`Resources/matriksenerji.gif" gif:ImageBehavior.AutoStart="True"/>
</Border>
<Border Padding="5" Grid.Row="1">
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=Label}" FontWeight="SemiBold" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
</Border>
</Grid>
</Border>
</telerikControls:RadBusyIndicator>
</Grid>
</UserControl>
在Page.xaml中使用
<UserControl x:Class="Eigen.Modules.Modelling.Components.BusyIndicator"
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:local="clr-namespace:Eigen.Modules.Modelling.Components"
xmlns:telerikControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d"
d:DesignHeight="150" d:DesignWidth="150"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid Width="{Binding Width}" Height="{Binding Height}">
<telerikControls:RadBusyIndicator IsIndeterminate="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=IsIndeterminate}">
<Border BorderBrush="White" Background="#A9FFFFFF" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Padding="5,0" Grid.Row="0">
<Image gif:ImageBehavior.AnimatedSource="/`enter code here`Resources/matriksenerji.gif" gif:ImageBehavior.AutoStart="True"/>
</Border>
<Border Padding="5" Grid.Row="1">
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=Label}" FontWeight="SemiBold" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
</Border>
</Grid>
</Border>
</telerikControls:RadBusyIndicator>
</Grid>
</UserControl>
错误消息
System.Windows.Data错误:40:BindingExpression路径错误:“在对象”“BusyIndicator”“上找不到IsProgress”属性
(名称=“”)。BindingExpression:Path=DataContext.IsProgress;
DataItem='BusyIndicator'(名称='');目标元素是“BusyIndicator”
(名称=“”);目标属性为“可见性”(类型为“可见性”)
ViewModel类具有“IsProgress”属性,但无法绑定到usercontrol。您可以尝试跟踪:
Visibility="{Binding IsProgress, , diag:PresentationTraceSources.TraceLevel=High, Converter={StaticResource BoolToVisConverter}}"
我建议你看看这里:
在用户控件定义中,您有以下行:
DataContext="{Binding RelativeSource={RelativeSource Self}}"
这意味着该控件的DataContext就是控件本身。因此,WPF正在尝试在此控件中查找IsProgress属性。
据我所知,IsProgress属性是在页面的ViewModel中定义的
所以最好的解决办法就是去掉上面的线
另外,要修复控件中的宽度和高度绑定,请向它们添加
RelativeSource={RelativeSource AncestorType={x:Type UserControl}}
。Page.xaml的datacontext是什么?一个viewmodel类@达雅人
DataContext="{Binding RelativeSource={RelativeSource Self}}"