我正在尝试读取包含在项目文件夹本身中的单独文件夹中的文本文件。我正在尝试读取此文本文件,然后将每一行添加到列表中,每一行作为列表中的一个单独项目,然后我希望将其绑定到列表框,并且每个列表框项目(以前的每一行)将是一个超链接在列表框中。这是非常令人沮丧的,因为一旦代码在运行时开始执行,应用程序每次都会冻结。可能是什么问题呢?
我试着在这里搜索了很多。我尝试了几个类似问题的解决方案,但没有用。
代码:
public partial class Page2 : PhoneApplicationPage
   {
       public Page2()
       {
           InitializeComponent();
           // Will contain the names of malls added through a text file
           List<string> Mall_List = new List<string>();
           using(StreamReader reader = new StreamReader("/Mall_List/Mall_List.txt"))
           {
                   while(reader.Peek() >= 0)
                   {
                       Mall_List.Add(reader.ReadLine());
                   }
                   reader.Close();
           }
               Malllist.ItemsSource = Mall_List;
        }
   }
XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox Height="426" HorizontalAlignment="Left" Margin="6,6,0,0" Name="Malllist" VerticalAlignment="Top" Width="444">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <HyperlinkButton Name="MallNameLinkButton"
                                         Content="{Binding}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>