I dont know if this is related to your issue, but there is currently a bug with the standard checkbox in WPF - when if you bind to the IsChecked value, it only triggers when the checkbox is checked and not when it is unchecked regardless of two way binding etc, which can cause some unexpected results. I believe this will be fixed in .Net v4 but it cost me tons of time scratching my head.
Anyhow, I took Ben's example and just expanded on it a bit more and it seems to be working fine with XElement. see below...
I made a converter class
public class IntToBoolConverter : IValueConverter
{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int intValue = System.Convert.ToInt32(value);
return (intValue != 0); //returns true for any non-zero value
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool) value == true)
return "1";
else
return "0";
}
}
Then in the XAML of the window place with the corresponsing namespace references
<Window.Resources>
<local:IntToBoolConverter x:Key="CheckBoxConv" />
</Window.Resources>
<Grid Name="myGrid">
<StackPanel>
<TextBox Text="{Binding XPath=@test1}" Height="30" Width="200"/>
<TextBox Text="{Binding XPath=@test2}" Height="30" Width="200"/>
<CheckBox IsChecked="{Binding XPath=@test2, Converter={StaticResource CheckBoxConv}}"/>
</StackPanel>
</Grid>
And then to test it, place the following in the window code behind.
public partial class Window1 : Window
{
private XmlDocument xmlDoc;
private XmlElement xmlElemMux;
public Window1()
{
InitializeComponent();
xmlDoc = new XmlDocument();
xmlElemMux = xmlDoc.CreateElement("Hello");
xmlElemMux.SetAttribute("test1", "1");
xmlElemMux.SetAttribute("test2", "0");
myGrid.DataContext = xmlElemMux;
}
}
And it seems to be binding correctly, and changing the value of xmlElemMux accordingly if I click the Checkbox or change the Textbox. The convertback portion could do with a little bit of tidying up... but this just illustrates the example.