2013-06-21 15 views
10

मैं डेटा बाध्यकारी का उपयोग कर एक सरल WPF अनुप्रयोग बनाने की कोशिश कर रहा हूं। कोड ठीक लगता है, लेकिन जब मैं अपनी संपत्ति अपडेट कर रहा हूं तो मेरा विचार अपडेट नहीं हो रहा है।WPF डेटा बाध्यकारी लेबल सामग्री

<Window x:Class="Calculator.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:calculator="clr-namespace:Calculator" 
     Title="MainWindow" Height="350" Width="525" 
     Name="MainWindowName"> 
    <Grid> 
     <Label Name="MyLabel" Background="LightGray" FontSize="17pt" HorizontalContentAlignment="Right" Margin="10,10,10,0" VerticalAlignment="Top" Height="40" 
       Content="{Binding Path=CalculatorOutput, UpdateSourceTrigger=PropertyChanged}"/> 
    </Grid> 
</Window> 

यहाँ मेरी कोड-पीछे है:

namespace Calculator 
{ 
    public partial class MainWindow 
    { 
     public MainWindow() 
     { 
      DataContext = new CalculatorViewModel(); 
      InitializeComponent(); 
     } 
    } 
} 

यहाँ मेरे विचार-मॉडल

namespace Calculator 
{ 
    public class CalculatorViewModel : INotifyPropertyChanged 
    { 
     private String _calculatorOutput; 
     private String CalculatorOutput 
     { 
      set 
      { 
       _calculatorOutput = value; 
       NotifyPropertyChanged(); 
      } 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 

     protected virtual void NotifyPropertyChanged([CallerMemberName] String propertyName = "") 
     { 
      var handler = PropertyChanged; 
      if (handler != null) 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

मैं नहीं देख सकता कि मैं यहाँ याद आ रही है है यहाँ मेरी XAML है? ? ओ.ओ

उत्तर

14

CalculatorOutput कोई गेटर नहीं है। व्यू को मूल्य कैसे प्राप्त करना चाहिए? संपत्ति भी सार्वजनिक होनी चाहिए।

public String CalculatorOutput 
{ 
    get { return _calculatorOutput; } 
    set 
    { 
     _calculatorOutput = value; 
     NotifyPropertyChanged(); 
    } 
} 
संबंधित मुद्दे