How soon we forget. A few years ago, I weaned myself off of Visual C++ and MFC and toyed (briefly) with ASP.NET
Now, I'm finally getting to grips with C#, .NET and CLR 4.0 and Silverlight.
And, all of a sudden, I'm thrust back to 1996. Why? Because we need to write a GINA (Graphical Identification aNd Authentication) component as part of a password reset application.
So, here we are, with definitely no CLR (which rules out C# and CLR) and recommended against the MFC. So, we're literally back in the days of defining dialog boxes as a set of resource definitions, and copious calls to CreateWindow. And that's before we get to the single threaded message pump that is WndProc.
Couple all of that with having to relearn C++ classes (compared to C#) and, most scarily, the fact that you need to clean up after yourself! malloc space for a string and remember that you need to free() them when you're done.
And here's another thing that never occurred to me; we're all used to googling for the answer, right? So, try googling on "create dialog" – you get pages of responses for C#, and VB, and ASP.NET, and SilverLight. You even get some response for MFC (whic you're not supposed to call from a GINA). But precious little for vanilla, plain WIN32 native code. Why? Because, by the time we all got to posting our every thought in blogs, forums, etc, the old fashioned way was dead and buried.
Get this; we're in the process of selling our home, with the plan to move elsewhere. As a consequence, we're renting some storage and we've moved all of what my wife calls "the crap", and what I refer to as "valued tomes of work that will help me in future years" into the most expensive garage-sized rental in Edinburgh. So, I went there last weekend and found, buried under a sea of DAT and DLT tapes, Citrix WinFrame manuals, and 56Kb modems, the book titled "Developing distributed applications with Visual C++ 6.0", circa 1999 – paper gold! It still expects me to be using MFC, so I still need to de-abstract (what's the real word for "de-abstract"?) a lot of it back to Win32 API, but it's reminding me of a whole load of concepts and techniques that I haven't used for almost 15 years.
Oh, and finally, the web may be a veritable desert of "how to do all of this the hard way", but I found one oasis; http://www.winprog.org/tutorial/
This has reminded me of everything I thought I already new, but had clearly forgotten.
Oh, and one final point… C#, SilverLight, CLR, ASP.NET, etc? These are "a good thing". I much prefer one line of code to perform a predictable task, compared to the 4 pages we used to take!
OK, I figured it out. How to present a data-bound combobox with Silverlight 4. This isn't going to work with SL2 or SL3 because they are missing the SelectedValuePath property.
So, let's set some context. I have a CredentialsType which, for the sake of this example, contains types which are;
- SNMP
- Windows
- SQL Server
- …etc…
Then, I have a CredentialsSet, which has a variety of login and password identifiers. So, for a Windows set, we have;
- CredentialsTypeId = the id of the CredentialsType we mentioned above, that is set to a CredentialsType where the CredentialsType.Name = "Windows"
- DomainColumn = the Active Directory domain name.
- LoginColumn = AD username
- PasswordColumn = AD password
Another CredentialsSet for an SNMP set may look like this;
- CredentialsTypeId = this id of the CredentialsType whose CredentialsType.Name = "SNMP"
- LoginColumn = SNMP Community string
So, the combobox is going to be on the CredentialsSet entity, pointing at the master (CredentialsType) record.
.png)
So, we have a master record for CredentialsType (primary key = CredentialsTypeId, Friendly Name = Name)
And the child record (in other words, the form that is displaying the record that is to be edited, that has a drop down relating to the parent record) has a number of child columns.
The XAML ends up looking like this;
<ComboBox Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="0,3,0,0"
Name="comboBox1" VerticalAlignment="Top" Width="120"
ItemsSource="{Binding ElementName=credentialsTypeDomainDataSource, Path=Data}"
DisplayMemberPath="Name"
SelectedValue="{Binding ElementName=credentialsSetDomainDataSource, Path=Data.CurrentItem.CredentialsTypeId, Mode=TwoWay}"
SelectedValuePath="CredentialsTypeId" />
Here, you'll see that;
- the ItemSource = the path to the data source that holds the complete list of elements (in our case, the CredentialTypes)
- DisplayMemberPath = The name of the property that will be displayed in the dropdown
- SelectedValue = the two way binding (i.e. ID) that links the child record to the parent record
- SelectedValuePath = this should be the same as the SelectedValue and points the caller to the correct value in the parent record
Excellent Silverlight 4 training session [...]
I had promised to post this to codeproject, but I wanted that article to be sooooooooooooooooooooo perfect… I spent days and weeks and months and years writing the article but never got round to finishing it.
In the meantime, a number of people have asked for the source to FileTreeView and, as promised, here it is!
http://www.scottleckie.com/wp-content/uploads/FileTreeView.zip
I'm an open kinda guy so if you have any suggestions or improvements, please add a comment, or email me, and I'll do my best to incorporate [...]
Edit; 26th May 2010; This is my most favorite post! Check out related Silverlight posts here…
Just getting started in Silverlight 4 WCF RIA Services (which is astonishing, by the way – check out Brad Abram's walkthrough here) but I was getting stuck at the validation part.
When I exercise the validation (you know, red bits in the browser because you're failing metadata requirements) and SubmitChanges, it was throwing up a horrible error;
An unhandled exception ('Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRunTimError
Message: System.ServiceModel.DomainServices.Client.DomainException: And error occurred while submitting changes…
The only funny bit about this was the typo; "And error occurred"… The dialog is shown here;
OK – I got an exception, let's debug… So, I click [...]
John Papa and Adam Kinney have posted a "Silverlight 4 Technical Features Overview" on channel9 (15th April 2010). Goes into good detail about all of the new SL 4 features and gives lots of sample code.
I'm hoping to use this to finally figure out databound combo boxes…
Rush over and read / print the entire 75 pages at Channel9
Covers; Business Application Development, Silverlight Toolkit, MS SL 4 Tools for VS2010, WCF RIA Services, Richer UI design, Expression Blend, O-O-B (Sandboxed and Trusted apps), and [...]
I'm passing a POCO to a Child Window, and the very first thing it needs to do is display a couple of properties from that object. So, I rattled off the basic code;
private MachineCredentials machineCreds { get; set; }
private BackupProviderType backupProvider { get; set; }
public RemoteBrowser(MachineCredentials machineCreds, BackupProviderType backupProvider)
{
this.machineCreds = machineCreds;
this.backupProvider = [...]
It occurred to me, tonight, as I copied and pasted the same generic log4net config to a new project that I do this because this is my favourite log4net configuration. And, if it's a good enough starting point for all my projects then it may be of interest to others.
This config writes to two appenders; the console and a file appender. The file appender is pretty neat in that it;
Creates log files in a logs/ folder
The standard file is "general.txt"
This file grows on each iteration, until it reaches a maximum size of 2MB
When it hits 2MB, the file is renamed and a new "general.txt" file is opened
Maintains a maximum of 10 renamed / archived log files (so, a total of 20MB [...]
log4net is a fantastic library for adding configurable logging to your project. Configuration is relatively straightforward but I always get caught out when adding it to a new project.
So, here's a cribsheet for adding it in…
Download the latest stable library, and add a reference to it within your own project
Ensure that you have an app.config file
Add the configSection for log4net (see samples, below)
Add the log4net section (another sample)
Add an ILog object to your class
And, the bit I always forget, add the [assembly] entry to the top of your class
In your app.config file, add log4net to the <configSections> (if you don't have one of these, it goes at the next level down from the <configuration> element;
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
Next, [...]
I did a bit of research while trying to figure out what I was going to move my blog to. I felt I was just too constrained at BlogSpot, and the ability to add tools / widgest / themes or to otherwise customise the blog was just too limiting.
Anyway (#1) I elected to go with WordPress because it seems open enough, powerful enough and simple enough (some oxymoron going on there) for what I wanted.
But the editor!!! Jeez. WordPress ships with a thing called TinyMCE which is actually pretty feature-powerful. But, a couple of postings in and the pain shines through.
Biggest gripes are;
#2 constantly having to switch between View and HTML mode to get the effect you want
#1 then [...]
|
|
Most popular