2017-06-05 12 views
-1

私には奇妙なエラーがあります。私は自分自身を取り除こうとしています。私は自分のアプリケーションのカスタムCur Cursorを作成しました。カスタムのカーソルをイメージフォルダのプロジェクトにロードし、それを自分のリソースに設定し、静的なクラスを作成してメディアストリームを開き、カーソルをウィンドウに渡しました。そこから私の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名前空間に存在しない名前:システム "

このエラーは間違っていますが、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; 
    } 
    } 
} 
+0

おそらく、 'POProperties'は(' POSystem'以外の)異なる名前空間にあるか、クラスではありません。いくつかの追加情報を提供する必要があります –

+0

質問にいくつかのコードを追加しました。 – ARidder101

答えて

0

私は静的プロパティメソッドを使用しようとせっかちだので、私はちょうど、インスタンス外にいない静的なアイテムとなりました非静的クラス内POPropertiesの静的インスタンス化を行いました。コードは次のように:

ウィンドウ:ウィンドウの背後に

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

コード:

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コード:

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)); } 
} 

この方法で私はもはや結合からすべてのエラーを取得していませんそれはうまくいく。私は質問にこの方法prierを知っていたが、私は静的なクラスのメソッドが良いだろうと思った。私は明らかに間違っていた。

関連する問題