Start a new topic
Solved

Data Standard XAML file Combo Box, populated from an Excel or CSV file

Wondering if anyone has populated a combo box in an XAML file from a list stored elsewhere, like in Excel or CSV.


thanks!

Kim


Hallo Kim

WPF brings an easy way to read values from xml files.


Of course you will need a xml file. In this example it is the PlotProfiles.xml

<?xml version="1.0" encoding="utf-8" ?>
<Profiles xmlns="">
	<Profile Name="Profile1">
		<Setting Format="kDefaultDrawingSheetSize" Printer="Microsoft Print to PDF" Colour="black" />
	</Profile>
</Profiles>

  

 In the windows resources of your xaml file you need to define an xmldataprovider and use your xml file as source

<XmlDataProvider x:Key="Profiles" Source="C:\ProgramData\Autodesk\Vault 2017\Extensions\DataStandard\Vault\Configuration\PlotProfiles.xml" />

 

 Then you can use the data provider in your combobox.

<ComboBox x:Name="cb_profile" DisplayMemberPath="@Name">
	<ComboBox.ItemsSource>
		<Binding 
		 Source="{StaticResource Profiles}" 
		 XPath="Profiles/Profile"
		/>
	</ComboBox.ItemsSource>
</ComboBox>

 

Best regards,

Thomas


that worked perfectly, thank you


Login or Signup to post a comment