2011-12-30 21 views
2

私はC#WPFプロジェクトを持ち、名前空間はtestです。 XAMLのサブネームスペースにはどのように名前を付ける必要がありますか?XAML名前空間の命名規則

<Window x:Class="test.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:local="clr-namespace:test" 
    xmlns:local.c="clr-namespace:test.Converters" 
    xmlns:local.v="clr-namespace:test.Validators"  
    Title="MainWindow" Height="360" Width="640"> .... 

ここで私は期間にサブパッケージを分離する規則を持っている...それは大丈夫ですか?

敬具、

E。

+0

。それは単なるローカルエイリアスです。 –

+0

私はC#の初心者ですから、人はいつも何を選んでいますか? :-o – emesx

+0

個人的に、私は階層を作成しません。そこには 'test'、' Converters'、 'Validators'があります。しかし、もう一度、 "何が効いていても"以外の規則はありません。 –

答えて

1

典型的なWPFアプリケーションでは、実際に一般的に現在の名前空間を参照しますデフォルトxmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"、ブレンド設計時の名前空間とxmlns:local以外のXAMLの名前空間規則を、持っていません。最後に

あなたは上記のシナリオでは

、私はいくつかの変種を使用/見てきた、すなわち、

<Window x:Class="test.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:local="clr-namespace:test" 
    xmlns:c="clr-namespace:test.Converters" 
    xmlns:v="clr-namespace:test.Validators"> 

または

<Window x:Class="test.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:local="clr-namespace:test" 
    xmlns:conv="clr-namespace:test.Converters" 
    xmlns:val="clr-namespace:test.Validators"> 

は、それが何であれ、あなたとあなた次第本当にですチームは同意する。

+1

ありがとうございます。 – emesx

9

可能であれば、使用するC#名前空間をWPF名前空間から分離することをお勧めします。これにより、あなたが持っている輸入数も減らすことができます。これはXmlnsDefinitionクラスのおかげでできます。あなたのライブラリのAssemblyInfo.csで

<Window x:Class="test.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:test="http://whatever.com/test"> 

、あなただけ追加する必要があります。

[assembly: XmlnsDefinition("http://whatever.com/test", "test")] 
[assembly: XmlnsDefinition("http://whatever.com/test", "test.Converters")] 
[assembly: XmlnsDefinition("http://whatever.com/test", "test.Validators")] 
[assembly: XmlnsDefinition("http://whatever.com/test", "test.CustomControls")] 

注意これが唯一のあなたが一つに異なるアセンブリ内のクラスがある場合に動作することそれらを参照してください。同じアセンブリ内では、C#名前空間を使用する必要があります。

あなたも、WPFのXML名前空間にあなたの名前空間を追加することによって、完全に輸入を排除することができます。人々は書くことができます

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "test")] 
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "test.Converters")] 
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "test.Validators")] 

を:あなたとあなたのチームが好きな

<Window x:Class="test.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    > 
    <!-- Note: no namespace prefix needed! --> 
    <YourCustomControl /> 
+0

ありがとうございました。私のクラスはすべて同じアセンブリにあります – emesx