|
This is the most general issue. You can access UI objects only from UI thread.
In WPF the UI thread is pointed using Dispatcher object. So you can replace the code
lstbOnlineClients.Items.Add(x);
with
this.Dispatcher.Invoke(DispatcherPriority.Normal, new System.Windows.Forms.MethodInvoker(delegate()<br />
{<br />
lstbOnlineClients.Items.Add(x);<br />
}));<br />
Dispatcher will invoke the code in the UI thread.
I hope this will help you.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
The OP already uses Dispather.Invoke.
|
|
|
|
|
Add a 'faked' item to a ListBox which serves as an "Add New Item" button.
The listbox is bound to an SQL database via Linq2Sq. I'd like to see sth like this:
- Apple
- Orange
- Banana
- (add a new fruit)
When users selects (add a new fruit), then it becomes an empty TextBox in which user can input data of a new item. On lost focus (or immediately, whatever), another "faked" item appears.
How can I achieve this?
Thanks
Greetings - Jacek
|
|
|
|
|
Add the PK of each item to the item's tag. Add the "(add a new fruit)" item with a tag of -1.
In the change, check for -1.
Everything makes sense in someone's mind
|
|
|
|
|
Do you mean that I should store the "(add a new fruit)" item in the DB? If then, how to prevent WPF from updating that row in the DB when user is actually overwriting it with a "mango" or whatever? Everything is done with data-binding, so I do not have much control, I do not add items manually...
Greetings - Jacek
|
|
|
|
|
No, return a dataset of items from the database. Then add a new row to the bottom that has the "(add a new fruit)" and -1 for a key.
Before update, remove the row.
Everything makes sense in someone's mind
|
|
|
|
|
Jacek - off the top of my head, I'd be tempted to use a CompositeCollection[^] in the ListBox ItemsSource . Inside this CompositeCollection , I'd have an observable collection of fruit, a separate entry for the (add a new fruit) and a separate entry for the textbox. The last two entries would be datatriggered so that only one was visible at a time (based on the logic of selecting to add a fruit). When you add a new fruit, the (add a new fruit) option moves down the list.
"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 have created my story board using expression blend but when i run the control it will run only once.but i need continues animation pls let me know wht i am suppose to do???
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
|
thanks it works...
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
I have the following XAML (there's actually more, but I thought it wouldn't be helpful since it's all the same only for different columns):
<ListView x:Name="InnerListView"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
x:FieldModifier="public"
BorderBrush="Black" BorderThickness="1"
ItemsSource="{Binding}" >
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Downloads" />
</GridView>
</ListView.View>
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel >
<Grid DockPanel.Dock="Right" >
<Label Grid.Column="1" Content="{Binding Path=WpfDownloads}" />
</Grid>
and in the code, I'm setting the list views data context to the observable collection of objects I'm trying to display:
InnerListView.DataContext = myList;
However, when the listview is displayed, all of the columns show "Namespace.Object".
What am I doing wrong?
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Is the path absolutely correct? It looks like you should be looking at a subproperty here, e.g. WpfDownloads.DownloadName. Without seeing the underlying code, I can't comment any further.
"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
|
|
|
|
|
WpfDownloads is a property of the object (derived from INotifyPropertyChanged ) contained in the observable collection. The set part of the property is being called, but the get isn't.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Yes, it's a property of the object, but what type is it? Is it a class in its own right? If so, you need to bind to a property in the instance of WpfDownloads (or you need to write a converter).
"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
|
|
|
|
|
Try this:
<ListView
x:Name="InnerListView"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
x:FieldModifier="public"
BorderBrush="Black"
BorderThickness="1"
ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Downloads">
<GridViewColumn.CellTemplate>
<DataTemplate>
<DockPanel>
<Grid DockPanel.Dock="Right" >
<Label Grid.Column="1" Content="{Binding Path=WpfDownloads}" />
</Grid>
</DockPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
|
|
|
|
|
Oh, and that Grid.Column="1" doesn't need to be there.
|
|
|
|
|
So why didn't you just edit your post
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Didn't feel like it. And thought it would be more obvious that I made a change if I replied to my own post. Would have been even more obvious if I replied to JSOP directly to notify him of my change (that way, he gets notified via email of the new post), but then I'd have to refer to my previous post and I didn't really want to deal with that.
|
|
|
|
|
Well, it actually is needed. I just didn't provide all of the xaml...
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
That worked. Now all I have to do is get past some of the built-in inability that is the ListView (no built-in sorting, no ability to freeze column widths, no ability to set a column that grows to fill remaining space, etc).
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
|
No worries - listview does it with some bullying.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Hi,
in a WPF application, I have two windows:
MainWindow - with the read-only ListView1 and the EditItem button
EditWindow - with Submit button.
After clicking on the EditItem button, a new EditWindow is shown, binded to the ListView1.SelectedValue . After clicking Submit , the updated values should be saved back to the underlying data classes and the ListView1 should be updated.
As far as I understand, the OneTime binding mode with explicit update is what I am looking for. Unfortunately, I have found no way how to set up the binding of the EditWindow in this OneTime mode (I do not see setting OneTime mode for each textbox as acceptable workaround).
How to open the EditWindow , bind it to the ListView1.SelectedValue and update it after clicking on the Submit button?
Currently, I have the following code for opening the EditWindow :
EditWindow frm = new EditWindow();
frm.Owner = this;
frm.DataContext = ListView1.SelectedValue;
frm.ShowDialog();
Thank you.
|
|
|
|
|
Hi,
This is just a guess, but maybe if instead of setting the edit form datacontext directly to the selected value, try using a one-time data binding instead there. This is just a guess.
|
|
|
|
|
Hi,
thank you for your tip and sorry for my delay in answering.
Unfortunatelly, One-time data binding means that the IDataError or ExceptionValidationRule logic would not provide user immediate feedback on invalid values. So I need something like data object transaction.
As a result, I have created a deep copy of edited data row and after submitting the edit form, I am copying the values back to the original row object. Quite boring, but as far as I know, there is no better solution.
|
|
|
|