-1

I have something of an odd error I am trying to rid myself of. I created a custom .cur Cursor for one of my applications. I have loaded the custom cursor into the project in an image folder, set it to my resources, and made a static class for to open the media stream to for it and pass the cursor to the windows. From there in my XAML I have the following code:

<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>

I found this method of binding to static classes here and it technically works. The problem is that even though i have built the project and even run the code successfully it shows an invalid markup error with the description:

The name "POProperties" does not exist in the namespace "clr-namespace:POSystem"

This error, however, is incorrect but it is causing me to be unable to use the XAML designer in Visual Studio.

The POProperties code:

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;
    }
  }
} 
ARidder101
  • 315
  • 2
  • 6
  • 16

1 Answers1

0

I got impatient with trying to use the static property method so I just made a static instantiation of the POProperties inside a now non-static class with no static items outside the instantiation. Code as follows:

Window:

<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"
        x:Name="Main" x:Class="POSystem.MainWindow" Title="Purchase Order" Cursor="{Binding 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">
            <TextBox x:Name="PONumLabel" Style="{StaticResource TBLabelStyle}" Width="250" Text="PO Number:"/>
            <myCtrls:DDTextBox x:Name="ItemsBox" Width="300" VerticalAlignment="Top" HorizontalAlignment="Left" MinHeight="25" Panel.ZIndex="1"/>
        </StackPanel>
    </Grid>
</Window>

Code Behind on Window:

namespace POSystem
{
  public partial class MainWindow : Window, INotifyPropertyChanged
  {
    private DataContext _data = new DataContext();
    internal DataContext Data { get => _data ?? new DataContext(); set => _data = value; }

    public MainWindow()
    {
      InitializeComponent();
      DataContext = POProperties.Instance;
    }    

    public void ClearFocus_OnClick(object sender, MouseButtonEventArgs e) { Keyboard.ClearFocus(); }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged([CallerMemberName] string Name = "")
    { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Name)); }
  }
}

POProperties Code:

namespace POSystem
{
  public class POProperties : INotifyPropertyChanged
  {
    public POProperties() { }

    private static readonly POProperties instance = new POProperties();
    public static POProperties Instance { get => instance; }

    private UserInformation uinfo = new UserInformation();
    public UserInformation GetUserInformation { get => uinfo; }

    private Cursor _ltc_cursor;
    public Cursor LTC_Cursor
    {
      get => _ltc_cursor ?? new Cursor(new MemoryStream(Properties.Resources.LTC_Custom_Cursor));
      set => _ltc_cursor = value;
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged([CallerMemberName] string Name = "")
    { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Name)); }
}

This method I no longer get any errors from the binding and it works well. I knew about this method prier to the question but i figured the static class method would be better. I was wrong apparently.

ARidder101
  • 315
  • 2
  • 6
  • 16