小编use*_*939的帖子

将数据从属性绑定到文本块 - MVVM Light和WPF

我在WPF中有一个文本块,它绑定到我的ViewModel类中的属性.单击按钮我希望修改属性并期望在我的文本块中反映出来.我希望所有这些都是纯粹使用MVVM(MVVMLight)完成的.我正在使用MMVM灯和VS 2012.挑战 - 在按钮上单击更改未反映.虽然程序执行是在属性内进行的,但是没有进行更改.

请帮忙 !!

程序视图:

<Window x:Class="MvvmLight1_Trail.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ignore="http://www.ignore.com"
    mc:Ignorable="d ignore"
    Height="500"
    Width="500"
    Title="MVVM Light Application"
    DataContext="{Binding Main, Source={StaticResource Locator}}">



<Grid x:Name="LayoutRoot">


    <TextBlock FontSize="34"
               Text="{Binding Path=MyText,UpdateSourceTrigger=Default, Mode=TwoWay}"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               TextWrapping="Wrap" />
    <Button Width="100" Height="100" Command="{Binding PressCommand}" Margin="198.985,277.537,193.014,92.462" Content="Press Me"/>

</Grid>
Run Code Online (Sandbox Code Playgroud)

查看模型

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using MvvmLight1_Trail.Model;
using System.ComponentModel;
using System.Threading;

namespace MvvmLight1_Trail.ViewModel
{

public class MainViewModel : ViewModelBase
{



    public RelayCommand PressCommand { get; private set; }
    Thread t;
    private string _welcomeTitle = string.Empty; …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml mvvm mvvm-light

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

标签 统计

c# ×1

mvvm ×1

mvvm-light ×1

wpf ×1

xaml ×1