1

或者这是一个不好的做法?在我的最后一个问题中,有人告诉我从后面的代码中引用/访问 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 本身中构建这些列表并仍然根据不同的按钮填充它?

4

0 回答 0