[英]Type reference cannot find type named… NOT because of missing assembly name
只是為了提前弄清楚這一點,我很清楚關於此錯誤的大量問題和答案,這是由於聲明中缺少程序集名稱而導致的,在此情況並非如此。
在過去的幾天里,我一直看到一些非常不穩定的代碼,它們似乎會停止編譯不正確的拋出錯誤,然后在關閉然后重新打開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}
它不像直接參考那樣干凈,但是它具有工作的好處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.