Hi, I have a question about binding a WPF control to a variable source. Presently, my controls are bound to an XML document which looks like this:
<data_type Id="conveyor_plc_data"><plc_type Id="Main"><plc Id="FeedCarousel" Active="" DataLen="100"><Item Id="Cmd" Active="True" DataLen="2" Type="Short" Value="0"/><Item Id="Data" Active="True" DataLen="2" Type="Short" Value="0"/><Item Id="ConvOffset1" Active="" DataLen="2" Type="Short" Value="0"/><Item Id="ConvOffset2" Active="" DataLen="2" Type="Short" Value="0"/><Item Id="CaroAngle" Active="True" DataLen="2" Type="Angle" Value="90"/></plc_type><plc_type Id="Backup"><plc Id="FeedCarousel" Active="" DataLen="100"><Item Id="Cmd" Active="True" DataLen="2" Type="Short" Value="0"/><Item Id="Data" Active="True" DataLen="2" Type="Short" Value="0"/><Item Id="ConvOffset1" Active="" DataLen="2" Type="Short" Value="0"/><Item Id="ConvOffset2" Active="" DataLen="2" Type="Short" Value="0"/><Item Id="CaroAngle" Active="True" DataLen="2" Type="Angle" Value="90"/></plc_type></data_type>
Here is the XAML definition for a particular control:
<RonM:CustomScrollBar Width="100" Height="100" HorizontalAlignment="Left" Margin="20,135,0,0" x:Name="EntryCarousel" VerticalAlignment="Top"><RonM:CustomScrollBar.Value><Binding Mode="OneWay" XPath="data_type[@Id='conveyor_plc_data']/plc_type[@Id='Main']/plc[@Id='FeedCarousel']/Item[@Id='CaroAngle']/@Value"/></RonM:CustomScrollBar.Value></RonM:CustomScrollBar>
Now the requirement is that sometimes the "Main" section of the XML document controls the action, and sometimes the "Backup" section controls it. Between each of those sections, the structure of the contents are identical except for perhaps the Value attribute.
So is there any way to make the "[@Id='Main']" part be variable, so it would equate to "[@Id='Backup']"?
I tried defining a String variable in the XAML and using a {StaticResource} tag within the XPath string, but that wouldn't work.
I would appreciate any ideas on how to solve this.
Thanks...
Ron Mittelman