|
Hi
Here's another simple question. I'm a newbie to WPF and I want to bind some data to a combobox. The data is coming from a Typed Dataset which I added via the VS2008 wizard.
Firslty, I instantiate the DataAdapter and the DataTable:
dsParrys_offoice_furnitureTableAdapters.ProductRangeTableAdapter daProductRange;
dsParrys_offoice_furniture.ProductRangeDataTable dtProductRange;
Then I fill the DataTable dtProductRange:
daProductRange = new aXYZ.dsParrys_offoice_furnitureTableAdapters.ProductRangeTableAdapter();
dtProductRange = daProductRange.GetData();
this.DataContext = dtProductRange;
I then want to display all the ProductRangeDescription in the listbox so I do the following:
cboStartupNew.ItemsSource = dtProductRange;
cboStartupNew.DisplayMemberPath = dtProductRange.Columns[1].ToString();
cboStartupNew.SelectedValuePath = dtProductRange.Columns[0].ToString();
cboStartupNew.SelectedValue = dtProductRange.Columns["ProductRangeDesc"];
When I enter debug mode and hover my mouse over cboStartupNew (tho combobox) it says that there are 17 items in the combobox, but still nothing displays in the combobox. Any ideas?
I tried using cboStartupNew.ItemsSource = ((IListSource)dtProductRange).GetList() as wellm but still no luck
|
|
|
|
|
What does your data template look like? There are much easier ways to display things in WPF, and it looks as though you are trying to use ASP.NET techniques rather than using the power of binding and templating in WPF.
"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
|
|
|
|
|
I'm not using a DataTemplate. I was under the impression that the binding will work even without one.
|
|
|
|
|
Hi,
I am working on a WPF application. In this I have a listview as
<ListView Height="271" HorizontalAlignment="Right" Margin="0,52,12,0" Name="lstvHistory" VerticalAlignment="Top" Width="181">
<ListView.View>
<GridView >
<GridViewColumn Header="Type" Width="50" />
<GridViewColumn Header="Description" Width="130"/>
</GridView>
</ListView.View>
</ListView>
In this dynamically I have to add one row at a time and later again one more row like that..
In this I have to add different data to the two columns of a row dynamically. For example for the first column I have to add 'MOVE' and second column 'LEFT' like this.
Please if any one have any idea how to do this please reply me.
|
|
|
|
|
You can create an appropriate data type (class) to hold the data.
Then you can bind the ListView to a collection (an ObservableColection<>
is a good coice here). Once you have that, you could use the DisplayMemberBinding
property of GridViewColumn to have the columns display the desired data from
your data type, for example
<GridViewColumn Header="Type" Width="50" DisplayMemberBinding="{Binding Path=Type}" />
<GridViewColumn Header="Description" Width="130" DisplayMemberBinding="{Binding Path=Description}" />
When you dynamically add or remove objects from the collection, rows will be added
or removed from the ListView.
Lots of info and examples here: Data Binding[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am developing one application in that I have more than 20 media elements.Here is the example for 5 media elements mp1,mp2,mp3,mp4,mp5.
And i am using i value from 1 to 20 based on the i value i have to use that corresponding media element.If i value is 2 i have to use mp2 and assign path to that mp2 source from code behind.
Those all media elements are created by default through design.Please can anybody help me how to resolve this problem or any suggestions to achieve this task.
Thanks in Advance
Pavani
|
|
|
|
|
Store references to each media element in a collection or array.
If they are stored in order, you can simple use an index to access
the references.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Merk thank you for your response.Can you please explain me clearly how to create references for media elements and how to store those references in array or collection because i am new to develpoment.
|
|
|
|
|
Here's two examples, using two different types of collections...
Using a Dictionary<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;
Dictionary<int, MediaElement> mediaElementDictionary = new Dictionary<int, MediaElement>();
mediaElementDictionary.Add(1, mp1);
mediaElementDictionary.Add(2, mp2);
...
int i = 1;
MediaElement mediaelement;
if (mediaElementDictionary.TryGetValue(i, out mediaelement))
{
}
Using a List<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;
List<MediaElement> mediaElementList = new List<MediaElement>();
mediaElementList.Add(mp1);
mediaElementList.Add(mp2);
...
int i = 1;
MediaElement mediaelement = mediaElementList[i - 1];
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark, Thank you very much for your clear explanation.I solved my problem through your explanation.Now I got how to use media element references using list and dictionary.
|
|
|
|
|
Hi,
I am developing one application in that I have more than 5 media elements.
I want to assign path to media element source from database.For that I have created one silverlight application and there is a ClientBin in silverlight website, I have saved my uploaded videos in clientbin and that path in database.
But from code behind if i assign the path its not showing anything.
my sample code is
mplayer.Source = new System.Uri(@"D:\sample\sample.Web\ClientBin\Lake.wmv", UriKind.Absolute);
Can you please tell me is there any other way to assign path to source property or what is the mistake I have done in that code.
Thanks in Advance
Pavani
|
|
|
|
|
pavanip wrote: mplayer.Source = new System.Uri(@"D:\sample\sample.Web\ClientBin\Lake.wmv", UriKind.Absolute);
You need to use URI strings that are appropriate for where the media actually is.
You're showing an absolute URI for aaa place on a hardrive - the client knows
nothing about a D drive, nor does it have access to its D drive. Besides, your
media is on the server, not on the client.
Here's a good article that should have what you need to know:
Different ways for loading images and files in Silverlight 2 applications [^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thank you for your response.I resolved my problem by using
mplayer.source=("Lake.wmv",UriKind.Relative) and I placed my video in web project ClientBin folder and directly using just video name.
|
|
|
|
|
hi peoples i m working in the WPF application,
i am having one border control in my application,
i need to hide the one side of the border for example ,
we will give border thickness for that..
how to give one side border thickness may be for the topborder alone can i give thickness as zero?
|
|
|
|
|
I suggest you buy a WPF book, and also consider reading the guide on how to ask questions.
When you specify a margin, you provide one, two or four values. If you provide one, it's used for all sides. If you provide two, one is used for top/bottom, the other for left/right. If you provide four, then you are specifying a thickness for each side explicitly. You need to do the last one, and provide zero for the side you want to have no border.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Christian Graus wrote: You need to do the last one, and provide zero for the side you want to have no border.
To be honest, it's not really obvious that you're supposed to do that. In the Properties pane, it shows a single value for BorderThickness, and applies that value to all edges. You have to google to find how to set thickness an edge at a time, but you also have to know that you *can* set it one edge at a time. The way I found out was by looking at custom control templates and I just happened to notice it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: In the Properties pane, it shows a single value for BorderThickness, and applies that value to all edges.
I NEVER use the designer for anything. Not in ASP.NET, not in Winforms, not in WPF. There's no substitute for reading a book, browsing the properties pane sure isn't the same thing.
I did think it was a reasonable question, it's something that one could overlook and need to be pointed towards.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
I have to use the designer to at least get initial layout accomplished. It's simply impossible to do layout without the designer. Many times, I just manually edit the XAML, but if there's a property in the pane, it's much faster just to set it and let the IDE do the typing.
Truth be told, anyone just starting out with WPF will also start out with the designer, simply because it's easy to see what's generally available as far as properties are concerned.
Lastly, even the intellisense in the XAML editor won't help you if you don't know you can type a dot and get more functionality. Admit it - the IDE bites, and I have yet to find a basic "WPF does it this way" kind of document. I wonder if there's a "WPF for Dummies" book out yet. I could certainly make use of it.
And if you want to hear something scary, I'm the resident WPF expert at work. If I don't know the answer, they have to hit google (just like me).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: Lastly, even the intellisense in the XAML editor won't help you if you don't know you can type a dot and get more functionality.
There's no magic in there.
It isn't any different than using .NET classes from code - you need to know the
data types of the properties you're using, and the public framework classes are well
documented. XAML throws a new language into the mix, so if you choose to use XAML
to set properties, you need to know the syntax for setting properties of the types
you use.
I highly recommend to anyone committing (or being forced to commit) to using WPF, to do
what I did...
1) open up the documentation
2) navigate to the WPF SDK (.NET Development/.NET Framework SDK/.NET Framework 3.5/Windows Presentation Foundation)
3) read it ALL - all of it - do not skip anything.
4) repeat step 3, this time trying some of the stuff you're reading about
5) (optional) if one is not a seasoned .NET programmer, one may want to invest in a book or two that breaks stuff down in simpler terms
It'll save you so much time down the road having a familiarity with how things work and
knowing where to find answers, instead of having to always weed through tousands of often
half-assed or completely wrong answers found via Google.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
John Simmons / outlaw programmer wrote: Truth be told, anyone just starting out with WPF will also start out with the designe
Maybe it's my ASP.NET background that makes me the exception. I don't expect too much from the IDE, I know better. The initial WPF support was shaky as hell, you think this is bad now ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Christian Graus wrote: When you specify a margin, you provide one, two or four values. If you provide one, it's used for all sides. If you provide two, one is used for top/bottom, the other for left/right. If you provide four, then you are specifying a thickness for each side explicitly.
BorderThickness, not Margin.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
*sigh* close, but no cigar....
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Christian Graus wrote: When you specify a margin, you provide one, two or four values. If you provide one, it's used for all sides. If you provide two, one is used for top/bottom, the other for left/right. If you provide four, then you are specifying a thickness for each side explicitly.
What Christian meant is BorderThickness, not Margin.
For example, for a border thickness of 2 with the top thickness 0:
<Border Width="100" Height="50" BorderBrush="Red" BorderThickness="2,0,2,2" />
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In my project I'm trying to get the mouse over an image and use the CaptureMouse event to move the image when I move the mouse. I'm able to move the image in the same direction as the mouse but the mouse isn't directly over the image. Here is what I have in my xaml file:
<Image Margin="116,76,113,176" Name="image1" Stretch="Fill" MouseLeftButtonDown="image1_MouseLeftButtonDown" MouseMove="image1_MouseMove" >
<Image.RenderTransform>
<TranslateTransform x:Name="imageTransform" X="0" Y="0" />
</Image.RenderTransform>
</Image>
Note: The image is inside a simple grid tag.
In my image_MouseLeftButtonDown down event I have:
image1.CaptureMouse();
In my image_MouseMove event I have:
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
test = Mouse.GetPosition(null);
imageTransform.X = test.X;
imageTransform.Y = test.Y;
}
Note: test is a Point datatype. The image follows the mouse but I can't figure out how to have the image follow the mouse when the mouse is over it. What am I doing wrong?
Terrance C.
|
|
|
|
|
Have you traced the mouse value you're getting ? I suspect the value you're getting is not absolute to your image. I would suggest storing the mouse position when you capture it, and on move, working out how far you've moved and moving the transform accordingly, instead of setting an absolute value.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|