【发布时间】:2017-11-06 14:57:18
【问题描述】:
我有一个奇怪的错误,我正试图摆脱自己。我为我的一个应用程序创建了一个自定义 .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>
我发现这种绑定到静态类here 的方法在技术上是有效的。问题是,即使我已经构建了项目,甚至成功运行了代码,它也会显示一个无效的标记错误和描述:
名称空间中不存在名称“POProperties” "clr-命名空间:POSystem"
然而,这个错误是不正确的,但它导致我无法在 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;
}
}
}
【问题讨论】:
-
可能
POProperties位于不同的命名空间中(POSystem除外)或者不是一个类。你应该提供一些额外的细节 -
我在问题中添加了一些代码。
标签: c# wpf xaml data-binding static-class