是否可以从数组中填充树视图?

时间:2013-02-22 00:29:08

标签: c# wpf

或者这是一种不好的做法?在我最后一个问题中,我被告知从后面的代码中引用/访问UIElements不是一个好习惯。  那么有没有更好的解决方案将数组发送到树视图?  我甚至不知道数组是否可以在这里使用,也许是一个字符串构建器。  我只知道这在我的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个不同的阵列。 这是我的一个数组的示例:

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中构建这些列表,并且仍然根据不同的按钮填充它?

0 个答案:

没有答案