« first day (547 days earlier)      last day (3602 days later) » 

4:55 AM
Hey guys, I'm trying to make a horizontal list of buttons. What I'm having trouble with is how to go about making that list dynamic. I have a list of strings and I want to display a button for each string in that list, and I also want those buttons' commands to be bound to the same command that will be able to figure out which button was clicked.
Does anyone have some advice on this?
 
5:15 AM
Sounds like an itemscontrol with a stackpanel Orientation = Horizontal
 
Would an example be pretty involved?
I'm going to start searching now
 
no I'll code one up for you
 
I'd imagine a template would be in order... somehow lol
 
@TheRedLou There you go
 
Oh man...
 
5:29 AM
I copy pasted the command code from internet cos lazy
think it looked correct at a glance
 
Do you remember helping me out about a year ago?
 
Ï didnt run it so it can be broken
 
When I was first learning WPF?
 
no my memory is poor
 
Haha, well you did. I was taking over a project and decided to use WPF and I spent a lot of time in here on WPF
Mainly getting started with MVVm
The code is perfect, ran immediately and does exactly what Im wanting
Now to learn what it's doing.....
I wanna show you what I've been working on if you'll be around
 
5:37 AM
@TheRedLou ask a bunch of questions
 <ItemsControl ItemsSource="{Binding ButtonInfos}">
^ that binds the itemscontrol to our collection of infos
 
<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
^ that tells the itemscontrol to use a stackpanel for its items, try changing to wrappanel or play with orientation
<ItemsControl.ItemTemplate>
    <DataTemplate DataType="{x:Type buttonsThing:ButtonInfo}">
        <Button Command="{Binding Command}" Content="{Binding Text}"/>
    </DataTemplate>
</ItemsControl.ItemTemplate>
^ that tells the itemscontrol to render each item as a button
<Button Command="{Binding Command}" Content="{Binding Text}"/>
^ that binds the buttons command to the command in the info and the content to the Text property
@TheRedLou sure
do you use git?
 
Modifying the ObservableCollection - does that update the button list at run time?
 
I do, but I was going to show you visually actually...
 
5:42 AM
ok
 
Can't share the code yet unfortunately....
 
but for the sample git is nice, then you can just play with the sample in a branch and always be able to revert back
 
Oh yeah, for sure.
I also like Gist
 
I updated the sample
now it adds buttons at runtime
 
Awesome!
 
6:00 AM
Works!
 
don't hesitate to ask if something is unclear
 
Stuck on one minor thing...
Can't add a button from a different ViewModel
Time for Inversion of Control
 
6:39 AM
@JohanLarsson That was nice
 
6:51 AM
Eventually I will get the hang of OOP lol
 
Well when I put a lot of effort into making my code well-structured and then I go to add a new feature, implement it partially, and then go to finish it and find out that I can't because I'm breaking my own rules lol.
 
Refactoring is not failure. It is evolution.
 
7:14 AM
@JohanLarsson Agreed.
 
7:28 AM
I dislike when I can't recreate an error...
 
do you write unit tests?
 
Sadly, I do not.
Not for this project anyway
I do for web stuff
 
ok it is very easy to get started, really small api for tests
 
Any recommendations?
(for testing WPF)
 
I use nUnit and R# testrunner
 
7:36 AM
Nuget?
 
yep nUnit is on nuget
you can use mstest, the difference is pretty small
other than that my recommendation is to keep the views clean, bind to the viewmodels
viewmodels are just classes and can be tested
I thought about tests when you wrote about recreating errors
they are not a guarantee but can be a way sometimes
 
Yeah I have tried to stay out of the views as much as possible
I have a ton of VMs
Hardly any code in my Views
 
sounds good
 
I want to set up testing
but I'm just not very good at it
mainly because I haven't sat down and learned it
it's not an excuse
 
it is life :)
 
7:49 AM
almost got that video up
can you watch youtube where you're at?
 
yep for a while at least, going to the stable to help gf with the horses later
 
8:14 AM
You'd think it'd be easy in this day and age to create a screen recording and put it on youtube but nope...
 
I have only done it once and it was a long time ago
 
Have you played around with dragging and dropping?
 
not much, wrote a thing once but don't know if I deleted it
rx can probably be really sweet for drag drop
 
8:31 AM
unit tests generally a separate project?
 
yes, to keep things clean
 
Video done...
Apologies for quality
 
Nice work man
Going to the stable now, we can play with drag/drop later sounds fun
 
Thanks. Alrighty, have fun!
 
9:10 AM
@MarinaNorova get somerep so you can chat, we need more regs :)
 
 
13 hours later…
10:19 PM
Wow
such activity
 

« first day (547 days earlier)      last day (3602 days later) »