c# - Caliburn Micro - 文本框中的文本不会显示

标签 c# wpf xaml caliburn.micro

我正在学习旧的 Caliburn Micro 教程 ( here )。我正在完成第 2 部分 ( here )。我已成功更新 App.xaml 和 AppBootstrapper.cs 以与 3.0.3 和 WPF 兼容(如此处“文档”页面上的“WPF”部分所述)。我使用的是 VS 2013。

本教程显示应用程序在初始化后出现值“50”。我的应用程序仅显示此内容:

enter image description here

这是到目前为止的代码:

App.xaml

<Application
xmlns:local="clr-namespace:CaliburnMicroApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class=" CaliburnMicroApp.App">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary>
                <local:AppBootstrapper x:Key="bootstrapper" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

AppViewModel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;

namespace CaliburnMicroApp.ViewModels
{
    class AppViewModel : PropertyChangedBase
    {
        private int _count = 50;

        private int Count
        {
            get { return _count; }
            set
            {
                _count = value;
                NotifyOfPropertyChange(() => Count);
                NotifyOfPropertyChange(() => CanIncrementCount);
            }
        }

        public void IncrementCount()
        {
            Count++;
        }

        public bool CanIncrementCount
        {
            get { return Count < 100; }
        }
    }
}

AppView.xaml

<UserControl x:Class="CaliburnMicroApp.Views.AppView"
             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">
    <Grid Width="300" Height="300" Background="LightBlue">
        <RepeatButton Name="IncrementCount" Content="Up" Margin="15" VerticalAlignment="Top" />
        <TextBlock Name="Count" Margin="20" FontSize="150" VerticalAlignment="Center" HorizontalAlignment="Center" />
    </Grid>
</UserControl>

AppBootstrapper.cs

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using CaliburnMicroApp.ViewModels;
using System.Windows;


namespace CaliburnMicroApp
{
    public class AppBootstrapper : Caliburn.Micro.BootstrapperBase
    {
        public AppBootstrapper()
        {
            Initialize();
        }

        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            DisplayRootViewFor<AppViewModel>();
        }
    }
}

最佳答案

将 AppViewModel 中的 Count 属性更改为公开。

关于c# - Caliburn Micro - 文本框中的文本不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42901496/

相关文章:

c# - 基于字符串的不变量 IComparer<string>

c# - 按键事件

c# - Items控制可点击的项目

wpf - 如何为 ItemsControl 中的项目添加边框?

c# - WPF 中的 Windows 8 选项卡控件样式

c# - "wrong"单元格上的 LinqToExcel 异常处理

c# - 使用 Selenium 完成 Internet Explorer 身份验证对话框

c# - X 和 Y 方向移动对象动画

c# - 是什么阻止了样式在运行时应用于 Silverlight 控件?

c# - 我们如何在 .net maui 7 中将单词包装在标签中