In order to get the attribute, you have to use a slightly different type of syntax. Rather than using XPath=name, you have to use XPath=@name. Now, that will only get you the value of the currently selected Kind item, so how do you actually get that item? Well, the answer is to use something like a ListBox to encapsulate the items.
Note: In this sample, I'm assuming that you have used an XmlDataProvider called MyEmulatorsList to point to this XML. So, where is the actual display of the name item? Well, that's provided by the ItemTemplate, which looks like this:
Dim data As XmlDataProvider = New XmlDataProvider()
PrivateSub MainWindow_Initialized(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Initialized
data.Source = New Uri(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\myapplication\Systems.xml")
data.XPath = "Emulators/System"
Grid1.DataContext = data
System.Windows.Data Error: 44 : BindingExpression with XPath cannot bind to non-XML object.; XPath='//Kind' BindingExpression:Path=; DataItem='String' (HashCode=2037252866); target element is 'ListBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') data
I think I see what the problem is. In the ListBox XAML, you don't need the Source=data (that's incorrect syntax, and besides, you already set the DataContext from the code-behind, so it's not needed. Take that part out, and it should work:
Thank you very much!! For the first time I can see those data displayed!!
Just one think... of importance:
ALL the "Kind" attributes are displayed.
I've tried a "IsSynchronizedWithCurrentItem="True"" but it doesn't change anything.
Any idea on how to fix it, please?
The datatemplate for the combobox that displays the system's "Name":
I 'd like to creatre a gallery control just like the built-in gallery in Windows Phone 7. I put a listbox in the grid to show the thumail image, but it cost many memory. And crashed soon after I loaded more than 80 pics(640*480). Could anyone give me a help?
In opinion it is not rocket sience but it does not work. I can set a breakpoint within the Converter(TelegramGroupStateToColor) and it will be hit and the correct color will be returned, but the backround remains transperent.
Has anybody an idea what I am doing wrong?
When the menu opens, the CanExecute is called with a command parameter == null! However it is called with the expected parameter immediately before executing the command. But as I want to have the CanExecute return value to depend on the command parameter (enable or disable the menu item), I need the correct parameter also when opening the menu.
Following is a test application to show the bad behavior (see program output for the passed parameter). I would be happy if somebody could help me. By the way, when I directly bind the parameter in MenuItem, everything works fine, but I don't want this because I want to dynamically build the menu using MVVM later.
I have a ListBox which is bound to an ObservableCollection, using some (complex) ItemTemplate to display the data. It is guaranteed that there is a fixed number of items within the ItemsSource.
Every time, the ObservableCollection changes (e.g., an item is replaced), a new ItemTemplate is generated. Can I somehow avoid this and instead reuse the existing template object and simply bind this to the new data?
I've bind an XML file to a ListBox.
Everything's working right..but the XML file is read as a resource for now...what I would like is being able to read it from the users/appdata/roaming folder! (that's where user's data are saved..so I would like to be able to read from there too!)
So, how should I adapt that 'Source=""' part to reference the users/appdata/roaming folder?
Amazing, it would never have occurred to me to bind and xml file directly to the UI, I would automatically have loaded the file into a collection in the viewmodel (or code behind) and then bound the collection to the listbox.
I should also note I never use xml!
Never underestimate the power of human stupidity