My issue is receiving a DataContext which has 1 XmlElement, and passing it to a Converter. The converter requires the complete element, because it works off of multiple attributes. The problem is it receives MS.Internal.data.xmldatacollection, which contains one XmlElement, and I can't figure out how to proceed.
<UserControl x:Class="W3.Views.ComboView" ...>
<ComboBox Style="{StaticResource ComboButtonStyle}" Width="auto" Height="auto"
Text="{Binding XPath=.,
Converter={StaticResource valueFormattingConverter }}" IsEditable="True" />
</UserControl>
The converter class:
[ValueConversion(typeof(XmlElement), typeof(string))]
public class ValueFormattingConverter : IValueConverter
{
public object Convert(object val, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType != typeof(string))
throw new InvalidOperationException("The target must be a List<string>");
if (val == null) return new List<string>();
XmlElement e = null;
if (val is string ) e = val as XmlElement;
if (e == null) return null;
return Information.XmlAccess.FormatXmlField(e);
}
So here, val is received as MS.Internal.data.xmldatacollection and I can't figure out how to deal with it to get the XmlElement it contains.
The vital context, which gets me the data: TOTAL
If we can fix it, the fix also needs to function in this more complex context:
<ContentControl x:Class="W3.Views.SimpleControlChooser" >
<ContentControl.Resources>
<DataTemplate x:Key="combo" >
<W3V:ComboView />
</DataTemplate>
// skipping other templates
</ContentControl.Resources>
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate" Value="{StaticResource combo}" />
<Style.Triggers>
<DataTrigger Binding="{Binding XPath=@format}" Value="check">
<Setter Property="ContentTemplate" Value="{StaticResource check}" />
</DataTrigger>
<DataTrigger Binding="{Binding XPath=@format}" Value="combo">
<Setter Property="ContentTemplate" Value="{StaticResource combo}" />
</DataTrigger>
//// skipping other DataTriggers
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
Right, so where is the data specified? Going up a level:
<UserControl x:Class="W3.Views.SimpleControl" ...>
...
<W3V:ControlLabel x:Name="Label" FontSize="12"
Width="{Binding LabelWidth,
RelativeSource={RelativeSourceAncestorType=W3V:SimpleControl}}" />
<W3V:SimpleControlChooser Content="{Binding}" />
I honestly don't understand the Content=line.
<ItemsControl ItemsSource="{Binding XPath=*}" Margin="0,0,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<W3V:SimpleControl x:Name="simple" Content="{Binding}"
LabelWidth="{Binding LabelWidth,
RelativeSource={RelativeSource AncestorType=W3V:PropertyView}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This usage currently works, and I don't want to break this one to get the other to work. I AM open to writing conditional code in the Convert() method to adapt to the data if it needs to be different.