« first day (1314 days earlier)      last day (2835 days later) » 

8:18 AM
morning
 
8:31 AM
hey
 
8:48 AM
Ugh. UI Virtualization woes. I have an Expander whose content contains a Listbox which isn't getting virtualized, probably because it doesn't have a Height defined.
The Expander is inside a grid row whose height is *, which is fine, but I'm guessing it being part of the expander screws with it.
 
9:06 AM
do you have some code to show @AvnerShahar-Kashtan ?
 
    <Expander Grid.Row="1"  Header="{Binding}" Style="{StaticResource IndicatorExpander}">
                            <ListBox MaxHeight="200"

                                     ItemContainerStyle="{StaticResource ListBoxSimpleItemContainer}"
                                     ItemsSource="{Binding Events}"
                                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                     ScrollViewer.CanContentScroll="True"
                                     SelectedItem="{Binding SelectedEvent}"
Going by this checklist, all items seem fine except for #3.
 
how do you know it's not getting virtualized ?
 
My ListBox has no height set, because I don't want it to.
Maybe I need to put a Grid around it.
@franssu Inspect it with Snoop/WPF Inspector, I can see that there are more ListBoxItem instances created than there are shown on screen.
 
there can be more instances even if virtualization is working
but I guess you're seeing a lot more instance than visible
 
9:21 AM
No, actually, just a few more. It might just be an optimization that automatically renders one or two items beyond the edge of the screen.
I'll need to try to find some sample data that has a lot more than is rendered, to see if it's really a problem.
 
it doesn't systematically dispose items which are no longer visible on screen
 
In this case, there are items in the tree that have never been visible - even before I touch the scrollbar.
But still, I see 5 items rendered when 3 are on-screen. It might be just some overflow, and not really a virtualization failure.
(This might not be a lot, but this listbox is inside another listbox, so there might be about 10 instances on screen, so they add up)
 
but if virtualization wasn't working, you would see all items instances
 
 
1 hour later…
10:34 AM
@franssu There are only 5.
 
@AvnerShahar-Kashtan You can resize the window to display only a single item and check again.
 
@NovitchiS Specifically the MaxHeight, yeah. I'll give it a try to see whether I'm barking up the wrong tree.
 
11:21 AM
Nope. Still renders 5.
But still, I have more promising widgets to profile and look for slowness, I think.
 
11:53 AM
Good morning!
 
 
1 hour later…
1:19 PM
'morning!
 
1:34 PM
o/
 
2:10 PM
Why would fetching about 4,000 records into an OC take forever?
 
is the OC bound to a listview?
rendering 4000 records can take time
 
Nope. I'm right now just running a test against it.
 
you ahve to figure out what is slow. i'd assume there are 3 parts to populating your OC
1) getting the data 2) converting to VM 3) adding to OC
 
so its probably your sql that is slow
not the actual filling of the oc
 
2:13 PM
No
Using LINQ to SQL against EF
 
just return the linq sql to a var, and remove the OC from the equation
see how long it takes
 
This is the technique I'm using: await Task.Run(() => new ObservableCollection<EmployeeViewModel>(query));
 
did that query already run? like does the collection already exist?
 
if you made a list of 10,000 strings, and then populated an OC, it would be isntant
populating an OC by itself is not an expensive operation
 
^
if there is a "loading" problem, its the control itself
 
2:16 PM
I'm not at that stage yet. Just testing the data service
 
you can test it yourself. make a fake employee view model, then add 4000 instances to your OC. that way you remove the sql from the problem
and you can see which part is being slow
 
whats the type of query?
 
I think it's IQueryable<EmployeeViewModel>
This SQL query works on MSMS and runs in a heartbeat:
select  e.* from Employee e
	left join employeestatus es
	on e.employeeID = es.employeeID
	where (es.validEmployeeStatusID not in (2,4)
		or es.validEmployeeStatusID is null)
Somehow the LINQ statement makes it choke
Can I run my own SQL statement and create an OC out of that?
 
run the query in code
then just do:
foreach(var e in query) { Console.WriteLine(e.Name); }
 
I love just good-old, plain SQL :)
Hmm. So populate the OC in the foreach?
 
2:31 PM
nope. just print each line
don't do anything with an OC yet
 
Ohh
OK
Let me try
I need to look up how to run a SQL statement in code
 
I'm not sure how IQueryable acts, but if its anything like IEnumerable<> the items don't actually exist until they are used.
 
@Alex wait what? I thought you had a query variable
 
I do, but can that contain plain old SQL? Or does it have to be LINQ?
The SQL works fine on Management Studio, the LINQ in my code, not so much
This should do what I need: stackoverflow.com/a/5630673/177416
 
2:35 PM
put a breakpoint on query
and put one on the Task.Run
 
As I have it currently in the gist, that beast never returns from the Task.Run
 
right, you essentially should try and figure out how long it takes for it to return query
so break before query, then run it until it finishes (breakpoint on Task.Run line) and how much time elapsed between the two
get rid of the await Task.Run
just return OC<VM>
if anything, you would me awaiting the query call
 
OK. Trying that now
 
i would hold off on doing any awaiting so you can realize the delays
so when it hits the first breakpoint, hit F5 and see how long it takes before it breaks on the last breakpoint
 
2:52 PM
I think I just figured out where the bottleneck is... it's when it's creating the VM
The SQL runs pretty darn fast
 
:)
 
In the VM, I'm calling the data service to populate 3 OCs, now multiply that by 4000
 
yeah that may be the issue.
 
that's over 9000
 
Ouch
When I was creating a few VMs it wasn't an issue
I need to make those properties static and populate them once
How would I only populate the properties once?
 
2:57 PM
how do you mean?
 
These values stay static across all EmployeeViewModel objects -- they're used for dropdown boxes -- jobs, organizational units, etc.
So if I fetch them only once, that suffices
I'm currently fetching the values and storing them in each VM
That was it!
Those darn calls to populate the OCs were killing me :)
Now I just do it once
 
3:16 PM
Wooo! Windows!
 
yeaaaah
my computer auto installed Windows 10 :D
or was, until it crashed during the install and rolled back to 7 :)
 
Dang. Aren't you guys using the GWX Control Panel? ultimateoutsider.com/downloads
 
@Alex you could probably store those lists outside of employee view models themselves and use RelativeSource for your bindings
 
That'll stop Windows 10
Julien: I'm thinking that's the way to go. Which object should hold those, though?
My solution with static has a code smell
 
the vm of the control that the employee list lives in
potentially, whatever VM holds your OC<Employee>
 
3:21 PM
But I also use the same VM in a different context... to create a new employee in a dialog. So in that case, there's no list, just one VM
I guess the parent VM that creates the dialog can set the OCs
Those should not reside the the EmployeeVM
They're higher level data that isn't specific to an employee
 
there's no right or wrong answer. just better solutions that come with experience
 
@franssu Use GWX Control Panel and no more worries about Win 10 pushing itself on you
 
ive said it before, figuring out how to scope your VM's is as much a part of wpf as actually coding
 
thanks @Alex
 
:)
@Julien Agree. I'm learning this now. Scoping those properties higher up makes sense now
I'll have to do some refactoring
 
3:26 PM
Hi
 
do you have a model layer @Alex
 
@franssu Yep. Entity Framework
Wrapped with view models
 
I've never used it much
 
lol. good. stay away
 
Some hate it, some love it
 
3:29 PM
Do you think that RDLC with WPF is a good tool for reporting?
 
It's my first serious ORM. Used Massive and ActiveRecord before, but those had been implemented by others
 
but I think your VM's structure should only reflect your models' structure
 
Very true. But for someone who was/is a noob, not knowing how to do RelativeSource to a parent view model... I threw a lot of stuff into VMs
 
where are your "jobs, organizational units" stored ?
 
Currently, in the EmployeeViewModel
 
3:31 PM
in the model layer I mean
 
They're not there. They're just a distinct call on a couple of columns on Employee models
 
@Alex this is only implementation details
so I think that's the source of your vm problem
 
Yep
It was going off into the wild, blue yonder when I tried to generate 4,000 of those little boogers
Now it's much faster
But I'd like to yank out those three properties and their database calls and put them elsewhere
 
you may want to have an entity like "CompanyInfos" in your model layer
 
The trouble is, the model layer is auto-generated by EF -- it's a database first design
If I make any mods to it, it'll be overwritten next time I update the models from the db
 
3:37 PM
CompanyInfos table maybe then ?
 
Yeah, but its data is generated on the fly
Maybe it can be a view
 
generated based on what ?
 
3 columns on Employee table
For example...
return new ObservableCollection<string>(context.Employees.Select(e => e.job).Distinct().OrderBy(e => e).ToList());
That returns the Jobs
 
and you're not in charge of designing the tables ?
 
I am
I designed the db :)
Fullstack, baby :)
 
3:40 PM
lol
 
:D
I wish we had someone to do that stuff, but I actually enjoy the db work
 
mmmh if your model is generated by database first design I think you should be grateful you have control over it
 
Next project, it'll probably be model first
 
so, do you have "jobs" and "organizational units" fields in your Employee table ?
 
Yep. Each is its own column
 
3:47 PM
some of which are the same for many employees ?
 
Yep, hence the call to .Distinct()
 
sorry I didn't see you pasted the query
 
No worries
 
hi everybody
how are you guys?
 
fine and you @FrancescoDS
 
3:51 PM
me too thanks @franssu
but I'm facing a little issue about a combobox
<ComboBox x:Name="PropertyList_Combobox"   SelectionChanged="PropertyList_Combobox_SelectionChanged" ItemsSource="{Binding Path=PropertyList, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name" SelectedIndex="{Binding Path=PropertyListCombobox_SelectedIndex}"/>
In my VM I have created the properties that I use for ItemsSource and SelectedIndex
I need to initialize the view with some data, so into the window constructor I call the VM constructor passing the items for PropertyList and the idx for SelectedIndex
when I set the PropertyListCombobox_SelectedIndex the PropertyList_Combobox_SelectionChanged is not raised
I've tried to move the intialization of the VM after the InitializeComponent() of the window...but nothing happens too
 
@Alex I don't want to bother your for too long but my point is wherever your model is implemented (in your case in your db), you really want to make it coherent, it's the central piece of your program. A job is an entity and should have its own table. An employee should reference his job by Id.
 
Notice that after the end of the initialization of the window, I can click on a button in the window that changes the value of the PropertyListCombobox_SelectedIndex, and the PropertyList_Combobox_SelectionChanged is correctly raised
 
sorry @FrancescoDS I don't have time now
 
no problem franssu...not urgent :)
 
 
1 hour later…
5:07 PM
@franssu Thank you! Totally agree with you
@FrancescoDS Wondering if it's something similar to this problem: stackoverflow.com/a/36779012/177416
That was a bear to solve
 
5:22 PM
Hi guys
 
5:37 PM
@FrancescoDS why are you using SelectedIndex instead of SelectedItem?
 
^ Good question
You can bind an instance of your ItemsSource to SelectedItem
 
 
1 hour later…
6:42 PM
If I have a Grid with its own DataContext, how do I bind an element to something in the parent's datacontext?
 
relativesource
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
that binding goes up the visual tree looking for a context menu
then binds against the contextmenu placementtarget datacontext
 
Nice! Thanks, Julien :)
Just what I needed
 

« first day (1314 days earlier)      last day (2835 days later) »