0

私は、数十の小さなツールの単なるコレクションである WPF プロジェクトを持っています。各ツールをメイン タブ コントロールのタブ項目に配置し、各タブ項目に対して部分的な MainWinow クラスを作成しました。ただし、ツール間の関連性はほとんどないため、ツール同士が干渉しないように、各ツールをシールすることをお勧めします。それに、部分授業は悪だと聞きました。ここでの問題は、MainWindow 以外のクラスが UI アイテムと通信するのが非常に難しいことです (私の知る限り)。私が行くべき場所の提案はありますか?

どうもありがとう。

Blam のリクエストにより、現在のコードを大幅に簡略化したバージョンを以下に示します。元のコードは大きすぎてここに貼り付けることができません。

xaml:

<Window x:Class="WpfApplication7.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <TabControl Margin="0,0,0,0" Name="tabControl1">
        <TabItem Header="Tool1" Name="Tool1">
            <Grid>
                <Label Name="lblTool1"/>
            </Grid>
        </TabItem>
        <TabItem Header="Tool2" Name="Tool2">
            <Grid>
                <Label Name="lblTool2"/>
            </Grid>
        </TabItem>
    </TabControl>
</Grid>
</Window>

部分クラス 1 (MainWindow.xaml.cs):

namespace WpfApplication7
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        string caption = "Tool Collection";
        public MainWindow()
        {
            InitializeComponent();
            this.Title = caption;

            InitialTool1();
            InitialTool2();

        }
        /*
            Some other methods for main window, including those for menu bar, tool bar, ... 
        */
    }
}

部分クラス 2 (Tool1.cs):

namespace WpfApplication7
{
    string tool1Details = "This is tool 1";
    /* 
        Other parameters related to tool1 
    */
    public partial class MainWindow : Window
    {

        public void InitialTool1()
        {
            lblTool1.Content = tool1Details;

        }
        /*
            Some other methods that communicate with tabitem1
        */
    }
}

部分クラス 3 (Tool2.cs):

namespace WpfApplication7
{
    public partial class MainWindow : Window
    {
        string tool2Detail = "This is tool 2";
        /* 
             Other parameters related to tool2 
        */
        public void InitialTool2()
        {
            lblTool2.Content = tool2Detail;

        }
        /*
            Some other methods that communicate with tabitem2
         */

    }
}

それらを部分クラスに分割する目的は、それらを異なるファイルに入れることができるようにすることです。

4

1 に答える 1

0

なぜ引っ張らないのか

    public void InitialTool2()
    {
        lblTool2.Content = "This is tool 2";
        /*
           Lot of codes that communicate with tabitem2
         */
    }

そして、他のすべての InitializeX を最初の Partial クラスに追加します。はメソッドに分離されていますが、それらと通信できますか?

于 2012-05-10T02:26:19.270 に答える