2012-01-10 6 views
-2

2つのXAMLファイルに.csファイルが1つありますか?2つのXAMLファイルにWPFで1つのcsファイルがありますか?

+14

この質問はどんな意味がありません。 –

+0

1つのcsファイルに対して2つのxamlファイルを持つことはできません。しかし、csファイル(つまりresourceDictionary)を持たずにxamlファイルを追加することができ、Csファイルで使用することができます。 – SharpUrBrain

+0

@Nikhil:あなたの必要条件は何ですか?なぜ2つのxamlファイルを持つcsを探しているのですか? 2 xamlファイルに1 csのファイルがある場合、どんな利点がありますか? – SharpUrBrain

答えて

5

はい、バッキングソースファイルには部分クラスしか含まれていないので、必要な場所に移動することができます。しかし、これはではなく、希望の練習です。

のUserControl1:

<UserControl x:Class="WpfApplication1.UserControl1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <TextBlock Text="UserControl1"/> 
</UserControl> 

UserControl2を:

<UserControl x:Class="WpfApplication1.UserControl2" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <TextBlock Text="UserControl2"/> 
</UserControl> 

出典:

namespace WpfApplication1 
{ 
    public partial class UserControl1 : UserControl 
    { 
     public UserControl1() 
     { 
      InitializeComponent(); 
     } 
    } 

    public partial class UserControl2 : UserControl 
    { 
     public UserControl2() 
     { 
      InitializeComponent(); 
     } 
    } 
} 
2

いいえ、それはできません。

これは簡単にMVVMパターンを使用して達成できますが、複数のXAMLファイル(閲覧回数)の同じcsファイル(モデルを表示)を保存することができます

あなたはなぜこれが必要なのか説明できますか?あなたが間違ったアプローチをしている可能性があります

関連する問題