我有一个奇怪的错误,我正试图摆脱自己。我为我的一个应用程序创建了一个自定义 .cur 光标。我已将自定义光标加载到图像文件夹中的项目中,将其设置为我的资源,并创建了一个静态类,用于为其打开媒体流并将光标传递给窗口。在我的 XAML 中,我有以下代码:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myCtrls="clr-namespace:UserControlsLibrary;assembly=UserControlsLibrary"
xmlns:pos="clr-namespace:POSystem"
x:Name="Main" x:Class="POSystem.MainWindow"
Title="Purchase Order"
Cursor="{Binding Source={x:Static pos:POProperties.LTC_Cursor}, Mode=OneWay}"
Height="850" Width="1100" Background="{StaticResource BackgroundImage}"
Icon="Images/logo_only_Xns_icon.ico">
<Grid x:Name="TheGrid" Focusable="True"
MouseDown="ClearFocus_OnClick" Background="Transparent">
<StackPanel x:Name="Panelicus">
</StackPanel>
</Grid>
</Window>
我在这里找到了这种绑定到静态类的方法,它在技术上是有效的。问题是,即使我已经构建了项目,甚至成功运行了代码,它也会显示一个无效的标记错误和描述:
名称空间“clr-namespace:POSystem”中不存在名称“POProperties”
但是,此错误不正确,但它导致我无法在 Visual Studio 中使用 XAML 设计器。
POProperties 代码:
namespace POSystem
{
public static class POProperties
{
private static Cursor _ltc_cursor;
public static Cursor LTC_Cursor
{
get => _ltc_cursor ?? new Cursor(new System.IO.MemoryStream(Properties.Resources.LTC_Custom_Cursor));
set => _ltc_cursor = value;
}
}
}