Total Newbie Question on BXF

Feb 19, 2011 at 1:48 AM

I am very new to BXF and relatively new to XAML.  I am trying to create a very simple MVVM Silverlight application that uses BXF and have hit a block.  I believe the issue is with my DataContext though I don't know how to fix it.

Here's how my project is set up.  I am using MVVM.  My model has a simple integer value, my view model has one method defined and my view (the XAML) has one button that I'm trying to get a TriggerAction to fire.  However, I set a break point in the method, click the button and nothing happens.  Can somebody please help me out?  I'm just not getting it for some reason:

My Model (SampleModel.cs)

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace TestBXF
{
    public class SampleModel
    {
        public SampleModel(int id)
        {
            Id = id;
        }

        public int Id { get; set; }
    }
}

My View Model (SampleViewModel.cs)

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TestBXF
{
    public class SampleViewModel : INotifyPropertyChanged
    {
        private SampleModel _model;

        public SampleViewModel()
        {
            _model = new SampleModel(0);
        }

        public void TestAction()
        {
            int i = 0;
            i = i + Id;
        }

        public int Id
        {
            get { return _model.Id; }
            set { _model.Id = value; OnPropertyChanged("Id"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

My view (MainPage.xaml)
<UserControl x:Class="TestBXF.MainPage"
    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:my="clr-namespace:TestBXF"
    xmlns:bxf="http://schemas.lhotka.net/1.0.0/bxf"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <UserControl.Resources>
        <CollectionViewSource x:Key="sampleViewModelViewSource" d:DesignSource="{d:DesignInstance my:SampleViewModel, CreateList=True}" />
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="92,116,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <bxf:TriggerAction TargetControl="{Binding ElementName=button1}" MethodName="TestAction" DataContext="{Binding Source={StaticResource sampleViewModelViewSource}, Path=CurrentItem}" />
    </Grid>
</UserControl>


I'm expecting this will be quite simple to solve but I just don't see it at this point in my new adventure with this technology.

Thanks in advanced,

Chris

Feb 21, 2011 at 12:56 PM

I've discovered over the weekend that there's a lot more I've got to do behind the scenes to make this work.  So, back to doing more research for now.  No real need for an answer on this question just yet.  That is, unless of course something is obviously missing with the start of my code for which I would appreciate instruction.

 

Looking more closely at the sample, I see I need to wire up the Presenter just to get out of the gates.