Posts from June 2009

Jun
30
2009

C#: XML with XDocuments



Posted in Programming

I’ve always used XmlDocument when I’ve needed to create or read XML, but I while I was implmenting a SOAP service for ChickenPing I discovered XDocument. XDocument offers a much more concise way of specying XML without all the boilerplate code.

For example, this snippet using XmlDocument:

XmlElement root = doc.CreateElement("recipeml");
XmlElement hdVersion = doc.CreateElement("version");
hdVersion.InnerText = "0.5";
root.AppendChild(hdVersion);
XmlElement hdGenerator = doc.CreateElement("generator");
hdGenerator.InnerText = "ChickenPing v" + Constants.GetVersion().ToString(3);
root.AppendChild(hdGenerator);
...

Read more »

Jun
13
2009

Editable ComboBox with XCeed DataGrid



Posted in Programming and WPF

I’ve recently started using XCeed’s DataGrid for WPF instead of he WPF toolkit DataGrid because overall it seems to have more features. One of the problems which I couldn’t find any reference to was using editable comboboxes when editing an item. I’m using an ObjectDataProvider as the ItemsSource for a ComboBox, but I wanted to let a user type a value as well as select one from the list.

The solution I eventually used lets a user add an item to the list of items which can then be selected when editing other items in the DataGrid.

Once you’ve declared the ObjectDataProvider in XAML, you need a CellEditor template for the column which will use the ComboBox (code below).

<xcdg:column .CellEditor>
    <xcdg:celleditor>
        </xcdg:celleditor><xcdg:celleditor .EditTemplate>
            <datatemplate>
                <combobox x:Name="cboMeasurement" IsVisibleChanged="cbo_IsVisibleChanged"
                      ItemsSource="{Binding Collection,Source={StaticResource measurementProvider}}" SelectedValue="{xcdg:CellEditorBinding}" IsEditable="True" Foreground="Black" IsSynchronizedWithCurrentItem="True" />
            </datatemplate>
        </xcdg:celleditor>
 
</xcdg:column>

Read more »