|
Are you sure that it's an ObservableCollection you are binding to? There's nothing magical about an ObservableCollection, except that for binding purposes it implements the ICollectionChanged interface and raises notifications when things have changed in it.
Check your Visual Studio output window to see if there are any binding errors in there causing it to fail.
|
|
|
|
|
You must be missing the ItemTemplate for the ListBox.
<ListBox Name=" "...>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=DirectiveName}"/>
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Try now.
People with high attitude deserve the standing ovation of our highest finger!
My Blog![ ^]
|
|
|
|
|
Hello,
I have a listbox bound to a DataView showing rows from a table (ReportingUser) in a typed DataSet. The table has a DataRelation to another table (Reporting). Hence the (typed) row objects have a ReportingRow property that refers to the corresponding row in the related table.
Each row is displayed using text from the Reporting related table:
<ListBox Name="listBoxSelectedReporting" ItemsSource="{Binding User/User_ReportingUser}"
DisplayMemberPath="Row.ReportingRow.ReportingName" />
I would like to sort the listbox by ReportingName as well. I have been struggling with this for two days. None of the solutions I found via Google work. They include:
1/ Use a SortDescription. But that mechanism doesn't seem capable of following property chains, unlike DisplayMemberPath.
2/ Grab the defaultView and set the Sort property. But the mechanism is string-based and gives access to the row's columns only.
3/ Cast the defaultView to a ListCollectionView and set a custom IComparer. But the cast fails.
I also had an idea: use a partial class definition to add a new property, to be used in SortDescriptions:
partial class ReportingUserRow
{
public string ReportingName
{
get
{
return ReportingRow.ReportingName;
}
}
}
Alas when I try to use it in either DisplayMemberPath or SortDescription, I get an exception that the property doesn't exist.
UPDATE: I can use my property in DisplayMemberPath like this: DisplayMemberPath="Row.ReportingName"
Which opens the question: using the debugger I see that my listbox contains a DataView that contains DataRowView objects which in turn contain a reference to a row object (of type ReportingUserRow). How does DataRowView find out what properties are available on a ReportingUserRow ? Why does it find the columns and not my extra property ?
modified on Wednesday, April 13, 2011 6:03 AM
|
|
|
|
|
1) I'm pretty sure that doesn't work... the implementation pretty much reflects on the current type and gets a property named "x". "Row.ReportingRow.ReportingName" is not the name of a valid property.
3) Should work just fine. I do it all over the place. How are you getting the default view? Show code. If the cast is failing, what IS GetDefaultView() returning?
|
|
|
|
|
Relevant lines from Window_Loaded:
dataset = new DNLMHDataSet();
reportingUserAdapter = new ReportingUserTableAdapter();
reportingUserAdapter.Fill(dataset.ReportingUser);
listBoxSelectedReporting.DataContext = dataset;
I run my program and make it break. In the Immediate window:
?System.Windows.Data.CollectionViewSource.GetDefaultView(listBoxSelectedReporting.DataContext)
{System.Windows.Data.BindingListCollectionView}
[System.Windows.Data.BindingListCollectionView]: {System.Windows.Data.BindingListCollectionView}
CanFilter: false
CanGroup: true
CanSort: false
Culture: null
CurrentItem: {System.Data.DataViewManagerListItemTypeDescriptor}
CurrentPosition: 0
Filter: null
GroupDescriptions: {System.Collections.ObjectModel.ObservableCollection<System.ComponentModel.GroupDescription>}
Groups: null
IsCurrentAfterLast: false
IsCurrentBeforeFirst: false
IsEmpty: false
SortDescriptions: {System.ComponentModel.SortDescriptionCollection.EmptySortDescriptionCollection}
SourceCollection: {System.Data.DataViewManager}
Let's try the cast:
?(ListCollectionView)System.Windows.Data.CollectionViewSource.GetDefaultView(listBoxSelectedReporting.DataContext)
Cannot cast 'System.Windows.Data.CollectionViewSource.GetDefaultView(listBoxSelectedReporting.DataContext)' (which has an actual type of 'System.Windows.Data.BindingListCollectionView') to 'System.Windows.Data.ListCollectionView'
When I look at the MS headers I see that both ListCollectionView and BindingListCollectionView derive from CollectionView. They're siblings, hence no cast...
|
|
|
|
|
So, um... didn't you just answer your own question???
In your particular case, you have a BindingListCollectionView, not a ListCollectionView. Simply cast the GetDefaultView() return into a BindingListCollectionView object and use that. GetDefaultView() actually returns an ICollectionView object. So, it is possible to get ANYTHING implementing the ICollectionView interface (like BindingListCollectionView in this case).
BindingListCollectionView implements everything you need. Like Comparer for example
|
|
|
|
|
SledgeHammer01 wrote: BindingListCollectionView implements everything you need. Like Comparer for example
...but the Comparer property is read-only And it has the SortDescriptions but it's useless for my purpose...
|
|
|
|
|
Oh right... sorry, yeah, I forgot some of the view classes randomly make useful properties read-only .
Ok, well, then there are a few ways you can proceed.
1) You are getting BindingListCollectionView because you are binding to a source that implements IBindingList. So you can repackage the data in something different like an ObservableCollection<T>, etc.
2) You can try wrap your source in a CollectionViewSource. CollectionViewSource requires the source to implement IEnumerable which should work for you.
#2 is probably easier, but if that doesn't work, you'll have to do #1 . It kind of makes sense that what you are trying to do is not really supported directly.
|
|
|
|
|
I tried yet another approach: sort the rows at the source, using this code:
dataset.ReportingUser.OrderBy(
row =>
{
System.Diagnostics.Trace.WriteLine("*** called ***");
return row.ReportingRow.ReportingName;
});
I tried putting it before and after the call to reportingUserAdapter.Fill(dataset.ReportingUser) but it is never called.
Feeling despaired...
|
|
|
|
|
I am trying to modify an RC remote controlled car so I can control it wirelessly from a wp7 platform but and I designed a masked textbox for an IP address input, I would like to know how the phone would wirelessly connect to the access point which is a router
|
|
|
|
|
At the moment, you can't. WP7 programming is still at the abstraction stage - in other words, it's been developed to make WP7 programming simple, so a lot of nuts and bolts stuff is hidden from you. This is unlikely to change in the near future.
|
|
|
|
|
OK, so I've worked with Winforms and Webforms for 20 years.
But now I've been thrown into building a Silverlight 4 application from scratch without ANY previous training. So please bear with me if I ask some questions here that seems stupid to people who have worked a lot with Silverlight before.
My first worry is: Do you really have to use WCF/Entity Framework services to access data from a Silverlight app. Can't you use the traditional ADO.Net objects (SqlDataConnection, SqlCommand, SqlDataReader etc) and access the SQL server directly like you can from a Webforms app?
The reason I ask is that my few tests have shown me that compared to a Webapp with ADO.Net data access, WCF and Entity Framework services are painfully slow. And since I know already from the specs that we need the performance to be absolutely optimal, I would prefer to do it the traditional way.
However, when I choose add reference in my Silverlight project and want to add System.Data.SqlClient, it's not there. That makes me wonder if it's not possible to use it.
????
TIA!
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
You're mixing things up a bit...
First, remember that a Silverlight application runs on the client side, not the server. The client uses WCF to communicate with a server-side process, and the server can use Entity Framework or ADO.Net to communicate with the database.
WCF = Communication framework, to send messages between the client and server (Or other things)
Entity Framework = A way to map database objects into CLR objects, to simplify data access... Basically a wrapper around ADO.NET.
|
|
|
|
|
Ian Shlasko wrote: You're mixing things up a bit...
I might be - as mentioned, this is a first for me. I thought the silverlight app was rendered from the server as is the case with a normal webapp. If it physically runs on the client, then I can (to a certain point) understand my mixup.
But then again: If I install a winform app on the client machine, then I can access a remote db directly without WCF, as long as I know the correct query string. Why isn't that possible in Silverlight?
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Johnny J. wrote: But then again: If I install a winform app on the client machine, then I can access a remote db directly without WCF, as long as I know the correct query string. Why isn't that possible in Silverlight?
You CAN have a Silverlight app go straight to the database, with the right security permissions and open ports on your network, though you're not really supposed to. Silverlight apps are supposed to access data by communicating with a server application, not by going directly to a database server.
So in short, the standard way to do it is:
Client-side SL App --[WCF]--> Server Application --[ADO/EF]--> Database
But if you cut out the server application and open your database to outside connections, you CAN do:
Client-side SL App --[ADO/EF]--> Database
EDIT: Ok, actually, I'm wrong about being able to do it that way... Silverlight isn't designed to go straight to a database at all...
http://forums.silverlight.net/forums/p/1350/3283.aspx[^]
|
|
|
|
|
Damn, damn, damn...
OK; thanks anyway. That does, however, make me wonder about whether or not it's worth creating the app in Silverlight...
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Depends on what you're trying to do... Right tool for the right job, and all that.
If you need it to be in a browser, you can have the Silverlight client query through a server app, go back to WebForms and do it server-side, or use a different platform entirely.
If being in a browser isn't really necessary, you can get all the power of Silverlight in a full-fledged WPF application (WPF is a superset of Silverlight), which can go straight to the database and do just about anything else.
|
|
|
|
|
Johnny J. wrote: O.Net objects (SqlDataConnection, SqlCommand, SqlDataReader etc) and access the SQL server directly like you can from a Webforms app?
We cannot access Ado.net objects directly from Silverlight.
Nor can you add the SQLClient as these don't exist with Silverlight.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
i am not a fan of wizards , i always do my database work myself. You said you have been writing software for 20 years and that means you have probably heard of the N-Tier architecture.
As an N-Tier Architecture evangelist, i am writing Silverlight applications and i am using that architecture. i have a BLL service and a DAL service, the DAL service with be exactly what you normally have ADO.NET and the BLL will be just consuming the public functions of the DAL and the Silverlight will consume the BLL functions like wise.
This has no performance problems and this is fast as ever and i have not experienced any problems. Silverlight does not support ado.net directly, this is because it runs on the client side. I am writing a series of articles on the N-Tier architecture in Silverlight. Check this for continuity of the subject
http://www.dotnetfunda.com/articles/article1154-building-an-ntier-architecture-application-in-silverlight-4-part-i-.aspx[^]
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
That does indeed seem like the best solution, but it still involves services - not direct db access, which I would have preferred...
I still don't see why a Silverlight app running on the client can't access a db directly using ado when basically all other types can (winforms, webforms and even WCF apps I'm told in another post in this thread)... Bummer. But my guess is that it's done that way to keep the size of the runtime to an absolute minimum.
I'll have a look at your article, though, and I think I'll be going with this solution in the end (if I don't decide against Silverlight all together).
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Silverlight does not support all the protocols that WCF have, so to create a WCF service that can be used by Silverlight , you need to use BasicHTTP. So if you look at your web forms , you will see that the controls have the "runatserver" property , that is why you could use direct ado.net.
But in silverlight everything is fully on the client side. the nice thing about silverlight comparing it to win-forms and asp.net is that there are other things that you don't need to worry about , things like the post back , cross browser compatibility and it can run as a web app and as a win form like app(Out-of browser). my java-script skills are not that good that is why i prefer to place a control at a certain location of a form and expect to find it there when i run my app. its a matter of preference.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I haven't seen this answer, so here's my attempt.
I'm not a Silverlight expert either, but I think Silverlight cannot access ADO.Net directly, because it is an application running ijn Internet Explorer, which is more or less a sandbox limiting possebilities. The reason why Asp.Net or WCF can access the database is because both run on the server (ASP.net does little more then generating text which the browser interprets as HTML).
in short, I think Silverlight is limited here because it runs inside the browser. Possibly there is a workaround...
V.
|
|
|
|
|
Hello,
I have a listbox of "users", when one is selected I want to display two listboxes: one containing the "reports" associated to the user, the other one the "other" reports. And buttons to move reports between the two listboxes. Very common scenario.
Users and reports are stored in a database accessed via ADO.NET. I have the following tables:
User: ReportingUser varchar(20) primary key
Reporting: ReportingCode varchar(20) primary key, ReportingName varchar(20)
ReportingUser: ReportingUser varchar(20), ReportingCode varchar(20)
I imported the tables in designer and added two Relations:
User_ReportingUser: ReportingUser.ReportingUser *->1 User.ReportingUser
FK_Reporting_ReportingUser: ReportingUser.ReportingCode *->1 Reporting.ReportingCode
The first relation is what my window edits. The second if for fishing the report name and display that instead of the report code.
I have the following XAML:
<ListBox Name="listBoxUsers" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" DisplayMemberPath="ReportingUser" />
<ListBox Grid.Row="1" Name="listBoxSelectedReporting" ItemsSource="{Binding User_ReportingUser}"
DisplayMemberPath="Row.ReportingRow.ReportingName" />
...and Window_Loaded handler:
userAdapter = new UserTableAdapter();
reportingUserAdapter = new ReportingUserTableAdapter();
reportingTableAdapter = new ReportingTableAdapter();
dataset = new DNLMHDataSet();
userAdapter.Fill(dataset.User);
reportingTableAdapter.Fill(dataset.Reporting);
reportingUserAdapter.Fill(dataset.ReportingUser);
listBoxUsers.DataContext = dataset.User;
listBoxSelectedReporting.DataContext = dataset.User;
It's amazing to see that this suffices to give me master/detail behavior. My first question is: why does this work? Is there a compact explanation of this somewhere ?
I googled around and did find information, e.g. about IsSynchronizedWithCurrentItem, but it's not enough to enlighten me. Where is the "current item" stored ? In listBoxUsers ? How is the other listbox aware that the current item has changed ? The "content" of the User_ReportingUser Relation is parameterized by the currently selected user. How does the ItemsSource of the Report listbox know which user is current ? What's the activity diagram ?
Also, now I would like to implement the reports that are not selected for the current user. First I tried to create a query for that but the designer only allows SQL code that returns a single value. So I created a TableAdapter with the following SQL:
SELECT ReportingCode, ReportingName
FROM Reporting AS r
WHERE (NOT EXISTS (
SELECT ReportingCode
FROM ReportingUser AS u
WHERE(ReportingCode = r.ReportingCode) AND (ReportingUser = @ReportingUser)))
Here again the "content" of the table is parameterized by the same ReportingUser. How can I make the listbox for the non-selected reports coordinate automagically with the User master control ?
|
|
|
|
|
Hello,
How to bind List of objects in the button's CommandParameter in Xaml.
Thanks in adv..
|
|
|
|
|
Without looking at your code it is impossible to tell. But you could try relative binding or element name binding. These would be able to pass the collection of objects to your view model code.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|