【问题标题】:UI (XAML) is not updating the properties But propertyChanged triggred in ViewModelUI (XAML) 没有更新属性但是在 ViewModel 中触发了 propertyChanged
【发布时间】:2015-01-05 13:54:31
【问题描述】:

我在更新 windows phone 8 中的 XAML 时遇到了问题...属性在 XAML 中与 viewModel 绑定,触发了 propertyChange 并更改了属性的值。但是 XAML 中的属性成员只在开始时更新一次,从那以后它不会更新 XAML 中的任何东西......虽然属性在 ViewModel 中不断变化......这些属性属于观察集合的列表,最后属于观察集合绑定到 LongListSelector

我已将绑定模式更改为“双向”,但无用我已粘贴下面的代码。

期待帮助。

视图模型:

    private string _description;
    public string description
    {
        set
        {
            _description = value;
            RaisePropertyChanged("_description");
        }
        get
        {
            return _description;
        }
    }

    private double _progress_bar_Value;
    public double progress_bar_Value
    {
        set
        {
            _progress_bar_Value = value;
            RaisePropertyChanged("_progress_bar_Value");
        }
        get
        {
            return _progress_bar_Value; //= ProfileSetting.ProfileTab_DOB;

        }
    }



    private double _Total_Bytes;
    public double Total_Bytes
    {
        set
        {
            _Total_Bytes = value;
            RaisePropertyChanged("_Total_Bytes");
        }
        get
        {
            return _Total_Bytes;

        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

XAML:

`

                                    >
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,0" Orientation="Vertical" 
                                    >
                            <TextBlock Text="{Binding description}"
                                       FontSize="18"
                                       TextWrapping="Wrap"
                                       Foreground="White" x:Name="Totalsize"
                                       />
                            <ProgressBar x:Name="Download_progressBar" 
                                         IsIndeterminate="False" 
                                         Maximum="100" 
                                         Height="10" 
                                         Width="400" 
                                         Value="{Binding progress_bar_Value}"
                                         Foreground="White"
                                         />
                            <TextBlock Text="{Binding Bytes_received}"
                                       FontSize="18"
                                       TextWrapping="Wrap"
                                       Foreground="White"
                                       x:Name="Total_received"
                               />
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>`

【问题讨论】:

  • 去掉 _propertyName 参数需要匹配属性名称,而不是支持字段。

标签: c# wpf xaml windows-phone-8 mvvm


【解决方案1】:

Raise Property Changed on public property not backing field(由 @HighCore 评论)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 2014-03-25
    • 2011-02-08
    • 2021-06-22
    相关资源
    最近更新 更多