I would like to get comfortable again with C# so I decided to start with an "easy" one. I would like create a dictionary from a XML file and bind it to a combobox. These are my snippets:
XML
<configuration>
<Paths>
<add key="Path_DQM_CE_Prod" value="DQM-CE\DQM_CE_12.2.0_17615\QMConfigurationEditor.exe" />
<add key="Path_DQM_CE_Test" value="DQM-CE\QMConfigurationEditor.exe" />
</Paths>
</configuration>
Code-behind (works, I an iterate through the dictionary)
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
///read XML and store into dictionary
var xdoc = XDocument.Load(@"\\ServerXYZ\Settings_CAX_Startcenter\config.xml");
var Paths = xdoc.Root.Descendants("Paths").Elements()
.ToDictionary(a => (string)a.Attribute("key"),
a => (string)a.Attribute("value"));
}
XAML
<Grid>
<StackPanel HorizontalAlignment="Left">
<ComboBox ItemsSource="{Binding Paths}" DisplayMemberPath="Value.Key" />
</StackPanel>
</Grid>
Pretty sure my binding is wrong but Im unable to solve it