小编Kon*_*pas的帖子

UWP 数据绑定不适用于 ViewModel

UWP 和 MVVM 的新手我遇到了一个对你们中的许多人来说似乎很明显的问题。

在项目中,我有3个文件夹命名ViewsViewModelsModels包括一些文件作为图像波纹管看到:

Can't upload image yet (reputation):

http://i.imgur.com/42f5KeT.png

问题: 我正在尝试实施 MVVM。我已经搜索了数小时的文章和视频,但似乎总是遗漏一些东西。我有一些绑定,LoginPage.xaml然后我在里面的一个类中修改Models/LoginPageModel.cs。我的INotifyPropertyChangedLoginPageViewModel.cs 中有一个类,每次我的属性更改时,我都LoginPageModel.cs希望INotifyPropertyChanged该类触发,然后更改LoginPage.xaml视图中的属性。下面我有这些文件的内容。

这是我的LoginPageModel.cs代码示例:

using System;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace App_Name.Models
{
    class LoginPageModel
    {
        private NotifyChanges notify;

        public async void LogIn()
        {
            if (something is true)
                notify.LoginUIVisibility = Visibility.Visible;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的LoginPageViewModel.cs

using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.UI.Xaml;

namespace App_Name.ViewModels
{ …
Run Code Online (Sandbox Code Playgroud)

data-binding mvvm inotifypropertychanged uwp uwp-xaml

3
推荐指数
1
解决办法
2529
查看次数

UWP Custom ListView向下滚动

所以,我有一个listview,每当创建一个项目滚动到该项目(底部)时我都想要它.因为我正在使用MVVM,所以我找到了关于如何创建一个从listview继承的新控件的非常好的解释.问题是这个答案(第三个)是指6年前的WPF.我正在制作一个UWP应用程序,因此我复制了代码并尝试将其格式化为我的需求.下面的代码不会给出任何错误或异常,而是加载"ChatListView",因为我称之为完美,然后什么都不做.与原始代码相比,注释仅进行了一些编辑.

我能做什么 ?先感谢您!

public class ChatListView : ListView
{
    //Define the AutoScroll property. If enabled, causes the ListBox to scroll to 
    //the last item whenever a new item is added.
    public static readonly DependencyProperty AutoScrollProperty =
        DependencyProperty.Register(
            "AutoScroll",
            typeof(Boolean),
            typeof(ChatListView),
            new PropertyMetadata(
                true, //Default value.
                new PropertyChangedCallback(AutoScroll_PropertyChanged)));

    //Gets or sets whether or not the list should scroll to the last item 
    //when a new item is added.
    public bool AutoScroll
    {
        get { return (bool)GetValue(AutoScrollProperty); }
        set { …
Run Code Online (Sandbox Code Playgroud)

dependency-properties custom-controls observablecollection mvvm uwp

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