开发者

Help on WPF Databinding to ViewModel Property (Prism)

Greetings guys, hopefully somebody has fresher eyes and can help me pinpoint the problem here, I'm trying to create a small app with prism and the MVVM pattern, everything was working nicely up to this point, my commands are firing properly with the argument, however, the TextBlock here is not binding to the CurrentUserKey property from it's viewmodel as it should.

Anybody has any ideas? thanks in advance...

LoginView.xaml (only relevant parts for bre开发者_运维百科vity) ...

<Grid DataContext="{Binding Path=., Source={StaticResource viewModel}}">
  <Grid Margin="10">
    <Label  VerticalAlignment="Center" HorizontalAlignment="Right">Enter your Key:</Label>
    <TextBlock Name="txtUserKey" Text="{Binding Path=CurrentUserKey}" Margin="2" />

    <Button cal:Click.Command="{Binding GenericButtonClick}" cal:Click.CommandParameter="7">7</Button>
    <Button cal:Click.Command="{Binding GenericButtonClick}" cal:Click.CommandParameter="8">8</Button>
    <Button cal:Click.Command="{Binding GenericButtonClick}" cal:Click.CommandParameter="9">9</Button>
...
  </Grid>
...

LoginViewModel.cs

public class LoginViewModel : ViewModelBase
    {
        public LoginViewModel()
        {
            GenericButtonClick = new DelegateCommand<string>(GenericButtonClickHandler);
        }

        private void GenericButtonClickHandler(string argument)
        {
            if (argument.Length < 2) {
                CurrentUserKey += argument;
            }

            RaisePropertyChangedEvent("GenericButtonClick");
        }

        public string CurrentUserKey { get; set; }
        private ICommand GenericButtonClick { get; set; }
    }

ViewModelBase.cs

public class ViewModelBase:INotifyPropertyChanged   
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChangedEvent(string Property_name)
    {
        if (Property_name == null) return;

        PropertyChangedEventArgs e = new PropertyChangedEventArgs(Property_name);
        PropertyChanged(this, e);
    }
}


You are not raising PropertyChanged when CurrentUserKey has changed.

Additionally, there are some issues with binding to Text in a TextBox: See http://social.msdn.microsoft.com/forums/en-US/wpf/thread/c404360c-8e31-4a85-9762-0324ed8812ef/ and WPF: TextBox Text is not updating

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜