Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows 8 Phone使用列表填充列表框的最简单方法<;字符串>;_C#_List_Xaml_Windows Phone 8_Listbox - Fatal编程技术网

C# Windows 8 Phone使用列表填充列表框的最简单方法<;字符串>;

C# Windows 8 Phone使用列表填充列表框的最简单方法<;字符串>;,c#,list,xaml,windows-phone-8,listbox,C#,List,Xaml,Windows Phone 8,Listbox,使用列表填充列表框的最简单方法是什么。那你会怎么发现这根绳子被敲击 List<HistoryEntry> urls = new List<HistoryEntry>(); public HistoryEntry selectedHistory; public MainPage() { InitializeComponent(); } void Browser_Navigated(object

使用列表填充列表框的最简单方法是什么。那你会怎么发现这根绳子被敲击

    List<HistoryEntry> urls = new List<HistoryEntry>();
    public HistoryEntry selectedHistory;

public MainPage()
        {
            InitializeComponent();
        }



 void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        // Save for fast resume
        _deactivatedURL = e.Uri;
        // We have arrived at a new page, 
        // hide the progress indicator
        _progressIndicator.IsVisible = false;
        textBox1.Text = Convert.ToString(e.Uri).Remove(0, 11);
        getHistory(textBox1.Text);
    }

private void getHistory(string url)
    {
        HistoryEntry urlObj = new HistoryEntry();
        urlObj.url = url;
        urlObj.timestamp = DateTime.Now.ToString("HH:mm yyyy-MM-dd");
        urls.Add(urlObj);

        listBox.ItemsSource = urls;
    }

    private void ListBox_SelectionChanged(object sender, GestureEventArgs e)
    {
        selectedHistory = listBox.SelectedValue as HistoryEntry;
        browserSearch(selectedHistory.url);
    }


<Grid>
                <ListBox x:Name="listBox" ItemsSource="{Binding urls}" Tap="ListBox_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>

                            <StackPanel Orientation="Horizontal">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"></ColumnDefinition>
                                        <ColumnDefinition></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel Grid.Column="1" Orientation="Vertical" Margin="0,0,0,29" >
                                        <TextBlock Text="{Binding timestamp}" FontSize="15" ></TextBlock>
                                        <TextBlock Text="{Binding url}" FontSize="25" ></TextBlock>
                                    </StackPanel>
                                </Grid>
                            </StackPanel>

                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
List url=new List();
公共历史条目选择历史;
公共主页()
{
初始化组件();
}
已导航的无效浏览器(对象发送者,System.Windows.Navigation.NavigationEventArgs e)
{
//保存以便快速恢复
_deactivatedURL=e.Uri;
//我们到达了新的一页,
//隐藏进度指示器
_progressIndicator.IsVisible=false;
textBox1.Text=Convert.ToString(e.Uri).Remove(0,11);
getHistory(textBox1.Text);
}
私有void getHistory(字符串url)
{
HistoryEntry urlObj=新的HistoryEntry();
urlObj.url=url;
urlObj.timestamp=DateTime.Now.ToString(“HH:mm yyyy-mm-dd”);
url.Add(urlObj);
listBox.ItemsSource=URL;
}
私有无效列表框\u选择已更改(对象发送方、GestureEventArgs e)
{
selectedHistory=listBox.SelectedValue作为HistoryEntry;
浏览器搜索(selectedHistory.url);
}
向列表中添加新值后,必须在列表框中看到这些值,如果点击其中一个值,程序必须显示已单击的值

提前感谢:)

如果您需要更多详细信息,请发表评论,我很乐意进一步详细解释:)

列表URL=new List();
公共主页()
{
初始化组件();
}
已导航的专用void WebBrowser_(对象发送方,NavigationEventArgs e)
{
stringurl=Convert.ToString(e.Uri).Remove(0,11);
HistoryEntry urlObj=新的HistoryEntry();
urlObj.URL=URL;
urlObj.timestamp=DateTime.Now.ToString(“HH:mm yyyy-mm-dd”);
url.Add(urlObj);
listBox.ItemsSource=null;
listBox.ItemsSource=URL;
}
公共类历史条目
{
公共字符串URL{get;set;}
公共字符串时间戳{get;set;}
}
列出URL=new List();
公共主页()
{
初始化组件();
}
已导航的专用void WebBrowser_(对象发送方,NavigationEventArgs e)
{
stringurl=Convert.ToString(e.Uri).Remove(0,11);
HistoryEntry urlObj=新的HistoryEntry();
urlObj.URL=URL;
urlObj.timestamp=DateTime.Now.ToString(“HH:mm yyyy-mm-dd”);
url.Add(urlObj);
listBox.ItemsSource=null;
listBox.ItemsSource=URL;
}
公共类历史条目
{
公共字符串URL{get;set;}
公共字符串时间戳{get;set;}
}

如果不想创建对象,请在代码中执行

List<string> myList = new List<string>();

//fill your list here

foreach (string sItem in myList)
{
    ListBox1.Items.Add(sItem)
}
List myList=new List();
//在这里填写你的名单
foreach(myList中的字符串sItem)
{
ListBox1.Items.Add(sItem)
}

如果不想创建对象,请在代码中执行

List<string> myList = new List<string>();

//fill your list here

foreach (string sItem in myList)
{
    ListBox1.Items.Add(sItem)
}
List myList=new List();
//在这里填写你的名单
foreach(myList中的字符串sItem)
{
ListBox1.Items.Add(sItem)
}
试试这个:

XAML:


政务司司长:

定义全局“ObservableCollection对象”`
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
基地。导航到(e);
obj=新的可观测集合();
对象添加(新数据(“string1”);
对象添加(新数据(“string2”);
对象添加(新数据(“string3”);
对象添加(新数据(“string4”);
lst.ItemsSource=obj;
}
//要向列表中添加新值,必须在列表框中看到
私有无效按钮\u单击(对象发送者,路由目标e)
{
增加(新数据(“新项目”);
}
公共类数据
{
公共字符串Str{get;set;}
公共数据(){}
公共数据(字符串Str)
{
Str=Str;
}
}
试试这个:

XAML:


政务司司长:

定义全局“ObservableCollection对象”`
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
基地。导航到(e);
obj=新的可观测集合();
对象添加(新数据(“string1”);
对象添加(新数据(“string2”);
对象添加(新数据(“string3”);
对象添加(新数据(“string4”);
lst.ItemsSource=obj;
}
//要向列表中添加新值,必须在列表框中看到
私有无效按钮\u单击(对象发送者,路由目标e)
{
增加(新数据(“新项目”);
}
公共类数据
{
公共字符串Str{get;set;}
公共数据(){}
公共数据(字符串Str)
{
Str=Str;
}
}
试试这个

private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
        {
             string url  = Convert.ToString(e.Uri).Remove(0, 11);
             HistoryEntry urlObj = new HistoryEntry();
             urlObj.URL = url;
             urlObj.timestamp = DateTime.Now.ToString("HH:mm yyyy-MM-dd");
             urls.Add(urlObj);
             listBox.ItemsSource  = null;
             listBox.ItemsSource = urls;
        }
试试这个

private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
        {
             string url  = Convert.ToString(e.Uri).Remove(0, 11);
             HistoryEntry urlObj = new HistoryEntry();
             urlObj.URL = url;
             urlObj.timestamp = DateTime.Now.ToString("HH:mm yyyy-MM-dd");
             urls.Add(urlObj);
             listBox.ItemsSource  = null;
             listBox.ItemsSource = urls;
        }

请确保将其添加到XAML中

<StackPanel x:Name="stack">
        <ListBox x:Name="lst">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Str}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Add new Runtime" Click="Button_Click"></Button>
    </StackPanel>

确保将其添加到XAML中<StackPanel x:Name="stack"> <ListBox x:Name="lst"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Str}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <Button Content="Add new Runtime" Click="Button_Click"></Button> </StackPanel>