|
Fixed:
Set the RichTextBox HorizontalAlignment to Stretch
|
|
|
|
|
Hi
Is there a way to populate a treeview using XML in WPF? Or by using the .xsd file?
If yes, please give me advice on how to get started. I've tried binding the treeview to the database using Hierarchical Datatemplates etc. but that still does not do the trick if you want multiple children nodes.
|
|
|
|
|
How about a short sample of the XML you're working with along with
how you're trying to bind to that XML...
Is the XML data actually hierarchical?
Also, searching on "wpf treeview xml data binding" yields tons of examples.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The thing is, I don't have a XML structure yet, I'm using a typed dataset which was generated for me by adding a datasource via the Visual Studio wizard, so I first have to generate a XML file from my typed dataset, and then bind it to the treeview. Here's a sample of what it might look like though:
<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <Products>
<ProductID>1</ProductID>
<ProductName>Chai</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit>
<UnitPrice>18</UnitPrice>
<UnitsInStock>39</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>10</ReorderLevel>
<Discontinued>false</Discontinued>
</Products>
- <Products>
<ProductID>2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
<UnitPrice>19</UnitPrice>
<UnitsInStock>17</UnitsInStock>
<UnitsOnOrder>40</UnitsOnOrder>
<ReorderLevel>25</ReorderLevel>
<Discontinued>false</Discontinued>
</Products>
</NewDataSet>
This is obviously just a basic table showing some Products, the database I'm going to be using will have sub levels as well e.g. A Product(above) can have multple Parts assoiciated with it, so that needs to be shown within Product and for each Product
|
|
|
|
|
What I also want to know, is say for instance you have 2 tables; Categories and Products. And the relationship between them is one-to-many (A category can have many products). Is it possible to generate an XML file showing all the different categories as well as the products belonging to them hierarchically?
<Category id=1><br />
<Product id=1><br />
<name>milk</name><br />
<description>white</description><br />
<price>3.00</price><br />
<Product id=2><br />
<name>cola&/name><br />
<description>black&/description><br />
<price>3.00&/price><br />
<Category id=2><br />
<Category id=3>
|
|
|
|
|
The UI part is relatively easy - here's an example (not I've added some
Parts to the Products so there would be some hierarchical data):
<Window x:Class="WPFTester.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Width="300" Height="250" >
<Window.Resources>
<XmlDataProvider x:Key="ProductData" XPath="*">
<x:XData>
<NewDataSet xmlns="" >
<Products>
<ProductID>1</ProductID>
<ProductName>Chai</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit>
<UnitPrice>18</UnitPrice>
<UnitsInStock>39</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>10</ReorderLevel>
<Discontinued>false</Discontinued>
<Parts>
<PartName>Part 1</PartName>
</Parts>
<Parts>
<PartName>Part 2</PartName>
</Parts>
<Parts>
<PartName>Part 3</PartName>
</Parts>
</Products>
<Products>
<ProductID>2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
<UnitPrice>19</UnitPrice>
<UnitsInStock>17</UnitsInStock>
<UnitsOnOrder>40</UnitsOnOrder>
<ReorderLevel>25</ReorderLevel>
<Discontinued>false</Discontinued>
<Parts>
<PartName>Part 1</PartName>
</Parts>
<Parts>
<PartName>Part 2</PartName>
</Parts>
<Parts>
<PartName>Part 3</PartName>
</Parts>
</Products>
</NewDataSet>
</x:XData>
</XmlDataProvider>
<HierarchicalDataTemplate DataType="Products" ItemsSource="{Binding XPath=Parts}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding XPath=ProductID}" Margin="0,0,6,0" />
<TextBlock Text="{Binding XPath=ProductName}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="Parts" >
<TextBlock Text="{Binding XPath=PartName}" />
</DataTemplate>
</Window.Resources>
<Grid >
<TreeView ItemsSource="{Binding Source={StaticResource ProductData}, XPath=*}" />
</Grid>
</Window>
In real life your XML data is dynamic, but you can bind to dynamically created XML,
for example: How to: Bind to XDocument, XElement, or LINQ for XML Query Results[^]
Creating the XML is outside the scope of this message board, but if you're
relatively new at it, I'd really recommend learning a bit of LINQ.
Using LINQ to XML and possibly LINQ to Dataset you'll have a consistent way to work with
both Dataset and XML data. For example, you can use LINQ to query a multi-table
dataset and build a hierarchical XML representation for presentation.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks I will have a look at LINQ. That sounds like it might do the trick.
So I guess there is no easy way to create a hierarchical XML structure based on a multi-table dataset. I though there might have been.
|
|
|
|
|
I just found out that when you're using untyped datasets, then you can manually set up a relation between your tables, and then you just set the Relation's Nested property to true, then when you generate an XML file it creates a beautiful hierarchical structure, just the way I want it.
BUT, I'm using a typed dataset, which means the relations are created for me. Is there a way to manually edit these relations?
|
|
|
|
|
I'm trying to hook the ReadFile API like FileMon does.
Do you have an example of ReadFile?
Please help me .....
|
|
|
|
|
You could always use this[^]. Your question has nothing to do with WPF, WCF or WF. In future, please take questions like this to a more appropriate forum.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
That's nice. I give you an answer and you give abuse. Tell me, which part of my answer actually offended you - the bit where I pointed you at actual code samples, or the bit where I pointed out that there were better places to ask these questions?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Don't react to quickly Pete. "maa chuda" is actually a South Glaswegian variant of the phrase "my chum" which means literally "he who is a friend of me". Used in this context the speaker is welcoming you into his inner circle of friends and thanking you for your help.
The believe traditional response is "och I"
I can see how that might have confused you.
Simon
|
|
|
|
|
Simon Stevens wrote: Used in this context the speaker is welcoming you into his inner circle of friends and thanking you for your help.
There are only certain people who have an inner circle that interests me.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
No one can abuse the great Pete!
|
|
|
|
|
Hi Pete,
I am sorry. I was really upset and I don't know wht really makes me to reply so badly.I am greatfull that u helped me.
I hope u will forgive me with a SMILE on ur face
|
|
|
|
|
Consider it done. No harm, no foul.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
*marked as offensive*
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am working on a WPF RSS feeds application. In this I want to display the RSS feed videos in the WPF page itself i.e., no external media player should open to play the RSS videos. How can I do this.
If any one have any idea to do this please reply.
Thanks in advance.
|
|
|
|
|
Hi All,
Has anyone encountered and worked around this problem?
I have a WPF app that uses the MediaPlayer class to get hold of WMP to play audio files. All is fine for a while playing various files then bang I get this error:
Unhandled exception at 0x1d1c1b30 in App.exe: 0xC0000005: Access violation writing location 0x3d0c3360.
I've wrapped all the neccessary bits in try{} / catch{} to isolate the issues but I fear it's actually out of my hands and may even be a bug in WPF or the MediaPlayer class itself.
I'm also attaching to the media player class MediaFailed event and that isn't getting fired when the error occurs.
Cheers,
|
|
|
|
|
Jammer wrote: playing various files
I thought I heard somewhere it was recommended to create a new media element/player for each file
because of some issue.
Or did I dream it...
*shrug*
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey Mark,
This may well be the case, It's all good for probably nearly 100 plays, then bang!
Hmm ... I may have to just start creating a new one after every 30 or so and see if that fixes the issue.
All far from good, but a solution nonetheless.
Cheers Chap,
|
|
|
|
|
I'm at a total loss on this. I've just set-up my class to create a new instance of a MediaPlayer every 30 'plays' of an audio file.
I've been running DebugView and running the app, I can't see any discernable pattern in what makes it crash. Nothing in the DebugView log jumps out either.
|
|
|
|
|
Hey, did you ever find a solution for this? Im having the exact same problem. It's very frustrating!!
Thanks
|
|
|
|
|
Yes I did.
I dumped Windows Media Player altogether. It was an unsatisfactory solution in the first instance anyway. I had a look around for decent .NET compatible playback libraries, there are quite a few around if you spend the time looking. I settled on a VERY feature rich and solid library called BASS which contains BASS.NET which handles all the comms to the C++ implemented playback engine. This is a seriously good audio library and it's worth the time looking into.
GET BASS
I've not had ANY issues with this component at all and it's in seriously heavy use in my app SampleSort.
Good Luck!
|
|
|
|