只是为了提前弄清楚这一点,我很清楚关于此错误的大量问题和答案,这是由于声明中缺少程序集名称而导致的,在此情况并非如此。
在过去的几天里,我一直看到一些非常不稳定的代码,它们似乎会停止编译不正确的抛出错误,然后在关闭然后重新打开VS后神奇地重新开始工作,还让我的自定义控件停止显示在设计器中并在ctor()中吐出幻像错误,然后自行修复,并且控件中的依赖项属性从VS属性资源管理器中丢失,但仍可以从XAML访问...。我想知道是否可能会出现一些bug。 VS,这是在我发现VS中的错误导致g.cs文件损坏之前发生的...
严重性代码说明项目文件行抑制状态错误类型参考找不到名为“ {clr-namespace:ODIF; assembly = PluginInterface}全局”的类型。CustomControls_WinX86 xxxxxxxxx \ CustomControls_WinX86 \ ChannelBoxMenu.xaml 17
为我的用户控件完成XAML:
UserControl x:Name="ChannelBoxMenuControl" x:Class="CustomControls_WinX86.ChannelBoxMenu"
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:CustomControls_WinX86"
xmlns:ODIF="clr-namespace:ODIF;assembly=PluginInterface"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="250">
<Grid>
<Menu x:Name="menu">
<MenuItem x:Name="menuItem" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Template="{DynamicResource MarginlessMenuItem}" Width="{Binding ActualWidth, ElementName=menu, Mode=OneWay}" Height="{Binding ActualHeight, ElementName=menu, Mode=OneWay}" >
<MenuItem.Header>
<local:ChannelBox Width="{Binding ActualWidth, ElementName=menuItem, Mode=OneWay}" Height="{Binding ActualHeight, ElementName=menuItem, Mode=OneWay}" Channel="{Binding SelectedChannel, ElementName=ChannelBoxMenuControl}"/>
</MenuItem.Header>
<MenuItem.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Source={x:Static ODIF:Global.ConnectedDevices}, Mode=OneWay}"><!--THIS IS WHERE THE ERROR IS THROWN-->
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Image Source="{Binding StatusIcon}" Width="16" Height="16">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding Icon}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding DeviceName}"/>
</StackPanel>
</HierarchicalDataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
</Menu>
</Grid>
</UserControl>
以及我引用的程序集中的相关代码:
namespace ODIF
{
public static class Global
{
internal static GlobalStore Store = new GlobalStore();
public static AsyncObservableCollection<InputDevice> ConnectedDevices
{
get
{
return Store.inputDevices;
}
}
}
internal class GlobalStore
{
internal AsyncObservableCollection<InputDevice> inputDevices;
}
}
同样值得注意的是,当我开始输入HierarchicalDataTemplate
ItemsSource的路径时,intellisense会选择路径ODIF:Global.ConnectedDevices很好并自动完成它,但是会引发找不到它的错误...。
尽我所能告诉我,关于上述原因为何行不通的并不是真正的解释。但是,如果有人遇到相同问题,对我来说,一种解决方法是在UserControl的类中创建一个静态属性,该类引用另一个程序集中的静态属性:
添加到ChannelBoxMenu:UserControl
public static AsyncObservableCollection<ODIF.InputDevice> ConnectedDevices
{
get
{
return Global.ConnectedDevices;
}
}
并将我的绑定修改为:
ItemsSource="{Binding ConnectedDevices, ElementName=ChannelBoxMenuControl}
它不像直接参考那样干净,但是它具有工作的好处。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句