それとも、これは悪い習慣でしょうか? 最後の質問の 1 つで、コード ビハインドから UIElements を参照/アクセスするのは適切ではないと言われました。配列をツリービューに送信するためのより良い解決策はありますか? ここで配列を使用してもよいかどうかさえわかりません。おそらくstringbuilderです。これが私のwinformで機能したことを知っているので、ちょっとそのままにしました。...とにかく、いくつかの配列をリストボックスに送信するチェックリスト アプリケーションを作成しました。
これは私のxamlです:
<ListBox x:Name="lstToDo" Margin="188,10,10,38" FontSize="14" SelectionMode="Extended" UseLayoutRounding="False" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding .}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</CheckBox.LayoutTransform>
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ユーザーが押したボタンに基づいて、そのリストボックスに送信できる約 50 の異なる配列があります。これは、私の配列の 1 つのサンプルです。
string[] Install_MySQL = {
"1. If you don’t have a SQL engine, install MySQL. ",
"a. MySQL Server 5.0",
"i. Typical",
"ii. Note: Select Custom if you want to install MySQL to a location other than the default, C:\\Program Files.",
"b. MySQL Server Instance Configuration Wizard",
"i. Select the Detailed Configuration radio button and click Next ",
"ii. select “Server Machine” if you expect to run other applications on this server ",
"iii. Select “Transactional Database Only”",
"iv. select the location for your Tablespace ",
"v. To allow for enough connections, select the OLTP option ",
"vi. Unless you have a specific reason for changing it, leave the default value of Port 3306.",
"vii. Standard Character Set",
"viii. accept the “Install As Windows Service” and “Launch the MySQL Server Automatically” ",
"ix. user: root pass: Synergy1 – enable remote access",
"x. execute – cross fingers ",
"c. Install MySQL Administration Tools for MySQL 5.0",
"i. mysql-gui-tools-com-5.0-r12-win32.msi",
"ii. select complete Install",
"2. More stuff",
"a. some more stuff",
"b. even more stuff",
};
これは、その配列をリストボックスに送信する方法です。
private void InstallMySQLTool()
{
foreach (string s in Install_MySQL)
{
lstToDo.Items.Add(s);
}
}
各サブリストを折りたたむことができるので、ツリービューがチェックリストのより良い解決策になると確信していますか? これらのリストを xaml 自体で作成し、さまざまなボタンに基づいてデータを入力する方法はありますか?