The data binding isn't working, what have I done wrong?

I'm writing a very simple WPF app, one view. I've got a few models defined for the small handful of tables this app works with. I'm making some sort of boneheaded mistake, but I can't see what it is. I'm trying to bind to a property of one of the model
classes I've define, to a textbox in a stackpanel. Here's the XAML:
<StackPanel Orientation="Horizontal" Margin="0, 5" DataContext="{Binding cvsSpecMapping}">
<TextBlock Margin="10,0,5,0">Specimen Mapping: </TextBlock>
<TextBox x:Name="txtHl7SpecMap"
Text="{Binding HL7SpecimenTypeName}"
ToolTip="{Binding HL7SpecimenTypeName}"
MinWidth="50"
MaxWidth="100"
MaxLength="250" />
</StackPanel>
Earlier in the same XAML file I've got the following collection view source defined in the windows' resources:
<CollectionViewSource x:Key="cvsSpecMapping" />
This isn't rocket science. Here's the model class definition. I'm removing all but the relevant property:
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace SpecMapException.Models
* This class I am interested in knowing what properties change.
* Also note that the properties in this class do NOT represent all of the properties
* in the Prism.SpecimenMapping table. It only represents what this application has
* to store.
public class SpecimenMapping : INotifyPropertyChanged
private const int MAX_HL7SPECIMENTYPENAME_LEN = 250;
#region class properties
private string _hl7SpecimenTypeName = "";
public string HL7SpecimenTypeName
get { return _hl7SpecimenTypeName; }
set
if (value != _hl7SpecimenTypeName)
_hl7SpecimenTypeName = EnforceMaxLength(value, MAX_HL7SPECIMENTYPENAME_LEN);
NotifyPropertyChanged();
#endregion //class properties
#region local routines
private string EnforceMaxLength(string PassedValue, int MaxLength)
if (PassedValue.Length <= MaxLength)
return PassedValue;
return PassedValue.Substring(0, MaxLength);
#endregion
#region PropertyChanged code
* The usual property changed code.
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
#endregion
And lastly here's the relevant code which I've put into the windows Loaded event:
Models.SpecimenMapping sm = null;
private void Window_Loaded(object sender, RoutedEventArgs e)
var cvsSpecMapNames = (CollectionViewSource)(this.FindResource("cvsSpecMapping"));
cvsSpecMapNames.Source = sm;
So what is the mistake that I've made? Why isn't the data binding to the textbox txtHl7SpecMap working?
(I'm using VS 2013, .NET 4.5.)
Rod

cvsSpecMapping is a resource and not a property so you should set the DataContext using the StaticResource markup extension instead of Binding:
<StackPanel Orientation="Horizontal" Margin="0, 5" DataContext="{StaticResource cvsSpecMapping}">
Also, the Source property of a CollectionViewSource is supposed to be set to a collection:
private void Window_Loaded(object sender, RoutedEventArgs e)
sm = new Models.SpecimenMapping();
var cvsSpecMapNames = (CollectionViewSource)(this.FindResource("cvsSpecMapping"));
cvsSpecMapNames.Source = new List<Models.SpecimenMapping>() { sm };
You may also want to set a default value of the HL7SpecimenTypeName property to confirm that the binding actually works after you have done the above changes:
public class SpecimenMapping : INotifyPropertyChanged
private const int MAX_HL7SPECIMENTYPENAME_LEN = 250;
#region class properties
private string _hl7SpecimenTypeName = "def....";
public string HL7SpecimenTypeName
get { return _hl7SpecimenTypeName; }
set
if (value != _hl7SpecimenTypeName)
_hl7SpecimenTypeName = EnforceMaxLength(value, MAX_HL7SPECIMENTYPENAME_LEN);
NotifyPropertyChanged();
Hope that helps.
Please remember to mark helpful posts as answer to close your thread and then start a new thread if you have a new question.

Similar Messages

  • HT5361 When inserting pictures in a new mail message using the " photo browser" button I can view and select photos but the " choose "  button is gone. What have I done wrong?

    When inserting pictures in a new mail message using the " photo browser" button I can view and select photos but the " choose "  button is gone. What have I done wrong?

    Hi Liz,
    Sorry to hear you are having a similar problem.  Last night I went to the tool bar at the top of iphoto, clicked on "File",  then clicked "Browse Backups" in the drop down menu.    I have an external hard drive that is set up to Time Machine.   The Browse Backups  opened the iphoto pages in the Time Machine.  I selected a date one day ahead of the day I performed the now infamous update, and it showed my iphoto library as it had existed that day.   I then clicked  "Restore Library" at the bottom right corner of the Time Machine screen.   Roughly 2 hours later my iphoto was back to normal.   When I opened iphoto there was a message saying I need to upgrade my program to be compatible with the new version of iphoto(version 9.2.1).  I clicked "Upgrade" and within seconds it had done whatever upgrading it needed to do. 
    The only glitch in the restoration was that it restored the library as it appeared last week, so I no longer had photos I had imported this past weekend.   I simply went back to the Browse Backups in the drop down menu,  when Time Machine opened I selected the page showing my pictures from this weekend and again said to Restore Library.   Roughly 45 minutes later the library was restored including the most recent photos.  
    I am now a happy camper. 
    I don't know if any of this will be of help to you because your email says you are having trouble with photos imported after the upgrade was performed.   Have you had any pop up notices when you first open iphoto,  that tell you you need an upgrade to be compatible with the new iphoto?     If so have you clicked "upgrade"? 
    Good luck Liz,  if you have Time Machine running as a back up to your library, maybe you wil be able to get help there, by following my instructions above.   Otherwise,   good luck with your investigations.   I'd be interested in hearing how you make out.
    Karen

  • I cannot get Adobe Reader 11 to work - what have I done wrong?

    I cannot get Adobe Reader 11 to work - what have I done wrong?

    Hi Pat,
    I usually don’t have trouble explaining my problems, but this one is confusing the heck out of me.  I just downloaded Reader 11.  It is installed, I believe.  This is the first time Reader has not worked for me after upgrading to a newer version.  I’ve been reading PDF files forever, but tonight when I went to read a pdf file that I received today, I clicked on the file, expecting Reader to open up and it never did.  Then I tried to read some older pdf files and nothing happened when I tried to open the file.  I’ve been using Acrobat Reader for years so that’s why I’m so confused.
    I downloaded the file from the adobe.com website. and everything seemed to be fine.  My question is indeed vague, but I don’t know any other way to explain what happened.  Should I uninstall and start over??
    Thanks, Elaine

  • I am trying to burn a DVD with a 50 minute video.  I repeatedly get the message that the content is too long.  What have I done wrong??

    I am trying to burn DVD with a 50 minute video.  I repeatedly get the message that the content is to long.  What am I doing wrong??

    Is this using iDVD?
    iDVD encoding settings:
    http://support.apple.com/kb/HT1502?viewlocale=en_US
    Short version:
    Best Performance is for videos of up to 60 minutes
    Best Quality is for videos of up to 120 minutes
    Professional Quality is also for up to 120 minutes but even higher quality (and takes much longer)
    That was for single-layer DVDs. Double these numbers for dual-layer DVDs.
    Professional Quality: The Professional Quality option uses advanced two-pass technology to encode your video (The first pass determines which parts of the movie can be given greater compresson without quality loss and which parts can’t.  The second pass then encodes those different parts accordingly) , resulting in the best quality of video possible on your burned DVD. You can select this option regardless of your project’s duration (up to 2 hours of video for a single-layer disc and 4 hours for a double-layer disc). Because Professional Quality encoding is time-consuming (requiring about twice as much time to encode a project as the High Quality option, for example) choose it only if you are not concerned about the time taken.
    In both cases the maximum length includes titles, transitions and effects etc. Allow about 15 minutes for these.
    You can use the amount of video in your project as a rough determination of which method to choose. If your project has an hour or less of video (for a single-layer disc), choose Best Performance. If it has between 1 and 2 hours of video (for a single-layer disc), choose High Quality. If you want the best possible encoding quality for projects that are up to 2 hours (for a single-layer disc), choose Professional Quality. This option takes about twice as long as the High Quality option, so select it only if time is not an issue for you.
    Use the Capacity meter in the Project Info window (choose Project > Project Info) to determine how many minutes of video your project contains.
    NOTE: With the Best Performance setting, you can turn background encoding off by choosing Advanced > “Encode in Background.” The checkmark is removed to show it’s no longer selected. Turning off background encoding can help performance if your system seems sluggish.
    And whilst checking these settings in iDVD Preferences, make sure that the settings for NTSC/PAL and DV/DV Widescreen are also what you want.
    http://support.apple.com/kb/HT1502?viewlocale=en_US

  • I downloaded adobe flashplayer as i couldnt see any video content on facebook. now all the videos i watch are jerky. ive tried to delete it off my harddrive and emptyied trash but still its no good. what have i done wrong/ and how can i fix it?

    I downloaded adobe flashplayer as i coulnt access video content on Facebook. now all the videos i watch jerk around. what have i done wrong and how can i fix it? I tried deleted the program to trash then emptyied trash but its still happening

    Try emptying your browser cache more often. If you are using Safari, from the menu bar top of your screen click Safari > Empty Cache
    Try a video on FB. If can't stream Flash content, back to the menu bar click Safari > Reset Safari. Select the top 5 boxes, click Reset.
    If that doesn't help, try deleing Flash cookies >  Flush.app – Flash Cookie Removal Tool For OS X | MacHacks.TV

  • I own Adobe Creative Suite 5 Design Premium Upgrade and I bought the upgrade to Adobe Creative Suite 6 Production Premium but it wont work with my serial number what have I done wrong

    Hi Mark,
    I own Adobe Creative Suite 5 Design Premium Upgrade and I bought the upgrade to Adobe Creative Suite 6 Production Premium but it wont work with my serial number what have I done wrong
    Mick

    Moving this discussion to the Downloading, Installing, Setting Up forum.
    Aussimick you will want to enter in the qualifying serial number from the full version of Adobe software you purchased.  You can find the serial numbers located under your account by following the steps listed in Find your serial number quickly - http://helpx.adobe.com/x-productkb/global/find-serial-number.html.

  • Is there a difference in the mac mini address book and my iPhone contacts? I have them both as well as my Ipad2 connected on I could but these don't seem to be sharing contacts. It worked in the store. What have I done wrong?

    Is there a difference in the mac mini address book and my iPhone contacts? I have them both as well as my Ipad2 connected on I could but these don't seem to be sharing contacts. It worked in the store. What have I done wrong?

    that should read all connected through I Cloud (fat fingers)

  • TS3276 Help!! I'm a fairly new MAC user. My Email has frozen on the computer. I cannot close Email to do a reboot. what have I done wrong and how do I correct the problem. My server is obviously working. thanks, Sharon

    My Email has frozen. I'm unable to close Email so I'm unable to reboot the computer. I'm a fairly new Mac user. What have I done wrong? And how do I resolve the issue? thanks, Sharon

    Force quit. cmd-option-esc key combo. Then choose Mail and force quit in the window that presents itself.

  • I found how to delete a series from my ipad, but it still won't download the last episode of the new series I am trying to have.  What have I done wrong?

    I found how to delete a series from my ipad, but it still won't download the last episode of the new series I am trying to have.  What have I done wrong?

    What is the GarageBand version that your friend is using?
    If it is GarageBand '11, version 6.0.5, you can buy GarageBand '11 as a boxed retail version with the iLIfe '11 bundle, e.g. from Amazon.
    Then you can upgrade GarageBand '11 to 6.0.5, using this upgrader from the Support page:
                     GarageBand 6.0.5
    GarageBand 6.0.5 will work well with your system.  But if your friend is using the newest GarageBand 10, this will not help. Then ask your friend to send you audio files for each track, so you can recreate the project from the audio.  Or your friend could also use GarageBand '11 for the projects you want to share, that will run well in all newer MacOS X versions, even with GarageBand 10.0 installed on the same system.
    -- Leonie

  • HT1386 I have a new computer. I have copied Itunes library from an external hard drive. Itunes now tells me I cannot sync with my Ipod as it thinks the 20gb on the computer are different to the 20gb on my Ipod touch! What have I done wrong? How can I fix

    I have a new computer. I have copied Itunes library from an external hard drive. Itunes now tells me I cannot sync with my Ipod as it thinks the 20gb on the computer are different to the 20gb on my Ipod touch! What have I done wrong? How can I fix it?  Alan

    See:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities
    Sync Your iOS Device with a New Computer Without Losing Data - How-To Geek

  • TS3989 I have just downloaded the latest Software, Lion, but i still don't have the Stream highlighted...what have i done wrong?

    I have just downloaded the latest Software, Lion, but i still don't have the Stream highlighted...what have i done wrong?

    That's what I was thinking but my neighbour did the 10.8 and got the 11 so can't understand how she got it and I didn't.
    I have been reading about iphoto 11 and there has been a lot of bad press when using with the iphone, ipad etc. Is it, in your opionion, too much hassle just for photo stream?
    Thanks so much for all your help...I thought i was gonna go mad, lol
    pvonk wrote:
    10.8 does not include iPhoto.  You need to buy iLife '11 at the Mac App Store.
    pvonk wrote:
    10.8 does not include iPhoto.  You need to buy iLife '11 at the Mac App Store.

  • After making a photopresentation and saved it as a quicktime mov with music i lost all tittles in the presentation, what have i done wrong?

    after making a photopresentation and saved it as a quicktime mov with music i lost all tittles in the presentation, what have i done wrong?

    Please, help me I have now 10 copies of my Photoslide show with music but still without the tittles(text) I added to the pictures. I used the original file name to add my text. Who know,s how to solve this problem or o I have to start again.
    Thanks for any help.
    Paul

  • I have downloaded adobe flash and it won't work. What have I done wrong?

    I have downloaded adobe flash and it won't work. What have I done wrong? I have even downloaded it twice (different versions). Is this a mistake?

    What is your operating system, version & edition?
    What is your web browser?

  • I am connected to my iMac to recharge iPad but it is saying "Not charging" ! Why and what have I done wrong?

    I am connected to my iMac to recharge iPad but it is saying "Not charging" ! Why and what have I done wrong?

    If you already updated to 8.0 you're doing nothing wrong. It's one of the lovely issues created by the update. I just tested mine, same problem.

  • Slideshow - does not run! What have I done wrong?

    It's stuck on the first image, does not run to the next.
    Can't remember that I done any changes. What have I done wrong?

    Perhaps an over simplified question, but have you selected more than the first image? Slideshow only runs for the images selected, and not all images in an album or project, unless selected. Sorry if this is too basic.
    Ernie

Maybe you are looking for