小编sac*_*ner的帖子

更改ObservableCollection后ListView不更新

我有一个ListView,我会在获取数据后立即更新.如果我在ViewModel的构造函数中向observableCollection添加项目,ListView会更新,但如果我在获得回调后在某些方法中执行此操作则不会更新.

我花了很多时间在Stackoverflow上,我知道有很多相关的问题,但我找不到答案.什么问题让我烦恼的是,如果我在构造函数中添加值时它会起作用,那么如果我在某个方法中添加值,它为什么不起作用.

  • 我正在使用ObservableCollection
  • 设置DataContext
  • 将ObservableCollection绑定到XAML中的ListView

这是XAML代码

<UserControl x:Class="WFP_Illustrated.UserControls.WeatherForcastControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         >
<UserControl.Resources>
    <Style TargetType="TextBlock" x:Key="TextStyle">
        <Setter Property="FontFamily" Value="Adobe Caslon Pro"/>
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="MinWidth" Value="60"/>
    </Style>
    <DataTemplate x:Key="ForcastTemplate">
        <Border BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding Path= Day}" Style="{StaticResource TextStyle}"/>
                <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Path= Condition}"   Style="{StaticResource TextStyle}"/>
                <Image Grid.Row="1" Grid.Column="1" />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="{Binding Path= Low}"  Style="{StaticResource TextStyle}"/>
                <TextBlock Grid.Row="2" Grid.Column="1" …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview observablecollection

5
推荐指数
1
解决办法
1万
查看次数

在C#中将参数传递给DownloadStringCompletedEventHandler

我正在研究WP7中的应用程序,我想将一个列表框作为参数传递给client_DownloadStringCompleted方法.

我的代码如下所示,

WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
Run Code Online (Sandbox Code Playgroud)

c# event-handling windows-phone-7

2
推荐指数
1
解决办法
1612
查看次数