« first day (2218 days earlier)      last day (1931 days later) » 

3:32 AM
3
Q: Why doesn't this storyboard defined in code work?

WillI'm attempting to create an animation for a GradientBrush that will animate each gradient to cycle through all of the colors contained within the gradient indefinitely. Because of the complex nature of this task, I've taken to handling everything in the code behind, rather than in XAML. Fortuna...

 
 
9 hours later…
12:53 PM
Hi all
 
 
1 hour later…
2:08 PM
Morning guys
What do you think about this:
if (something)
    return;
as opposed to let's say A:
if (something) return;
or B:
if (something)
{
    return;
}
 
For just return statements, I prefer A.
For simple assignments, the unnamed one.
For anything that would break into multiple lines (even if a single statement), B.
That is: I don't like long linq queries (in either syntax) to be in a conditional without being bracketed
 
Personally I would never recommend the unnamed one. Just because of the risk someone comes after and by mistake adds something without adding the braces
 
I'm going with B these days, because it's a team proj and others will look at code
 
Would you say that B is much better than A? like is it 1: B 2: A 3: unnamed, or 1: B 2: A 435: unnamed
 
2:25 PM
No, it's a matter of coding style and being consistent.
If you prefer A, then use that everywhere.
So other devs (and yourself in a few weeks/months) can tell that something that's a one-liner conditional won't have curly braces
 
I think R# is making all one-liners that look like A look like unnamed. I wonder if there's a setting....
I'm sure there is and I probably need to reconsider. But usually, the conditional determines if a usage is valid or makes a call. If it's a 'usage is valid' concern, it gets picked up pretty quickly. If it's a call, it depends on the call.
 
nae.. at least not my 2013 :)
 
3:02 PM
there is also
if (something)
{ return; }
 
That's almost as bad as:
if(something){
return;}
 
Yeesh
C# doesn't care, but oh, my eyes!
 
Yeah. I really strongly dislike same-line open and close brackets.
I don't care about my LOC numbers in either direction, but I despise same-line opens and closes.
</rant>
 
how about no line functions :) ? like when your implementing a interface and dont want a function to do anything.
void funcA() { }
void funcB()
{ }
void funcC()
{
}
:)
 
I don't have such strong preferences. But I think I bring a fun problem today. How do I paste code?
 
3:07 PM
just paste, then click the fixed font. Just don't paste to much
 
<DataGrid Name="grid"
                  AutoGenerateColumns="False"
                  HorizontalAlignment="Stretch"
                  ItemsSource="{Binding Items, Mode=OneTime}">

            <DataGrid.Resources>
                <Style TargetType="ComboBox" x:Key="cbStyle">
                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                    <Setter Property="Margin" Value="2"/>
                </Style>
            </DataGrid.Resources>

            <DataGrid.Columns>
I have a grid with a ComboBox column that I want to style like above. When I apply the style, the selection on the screen is incorrect - a consistent item for all rows. When I remove the style, everything works properly
 
For voids, I'd probably go with A, if it never needs implementing, and C (with a comment) if it's going to get one later.
For functions not returning void, I'd => value;
cudi: Generally, if it's long enough to need the "(Show full text)" link, we prefer you gist it (or pastebin, or whatever you please), so there's just a link in the chat. It keeps discussion more readable.
One sec while I read this
 
understood. Thank you. I'll follow next time.
 
So you're getting... One item in this column for every row?
Hm.
 
yes, same item. And if I change the selection, all rows change together
 
3:18 PM
mmm, snow
 
really? where?
 
So if I'm reading this correctly, `event_name` is the name of a property on an item in `Items`.
I'm....
I'm thinking
 
yes
 
So if you remove the ElementStyle attribute, the style isn't applied, and the comboboxes work as expected? Filled with the correct choices, and not tied together? That seems really strange.
I was suspecting the ItemsSource being a StaticResource and some strange CollectionView interaction, but if it works properly without the style, that rather rules that out.
 
that's what's happening.
 
3:23 PM
Have you tried SelectedItemBinding, instead of SelectedValueBinding?
(I know it seems unrelated)
 
you might be onto something with the CollectionView. I tried this on another column that binds to a string[] property and it doesn't have the same issue
 
Also possible: DataGrid columns also have an EditingElementStyle, and I wonder if a weird interaction is happening between the default for that and the style you're applying.
 
all I want is to center the text. Why does it have to be so hard :)
 
It's maybe possible to use BasedOn in the style to base it on the ComboBoxColumn's DefaultElementStyle, and that may help. I'm not sure what their style is doing, but there could be some weird interaction there.
 
good afternoon, Andrea from Italy here
 
3:28 PM
 
I'd like to do that. Let me look it up. Thank you
 
Hope it helps!
Howdy, Andrea. ow's the afternoon?
 
I'm new to WPF, and trying to do something for my current employer. I know (I think) enough C#, and I'm trying to code following MVVM principles
(yes afternoon is ok, near time to go home thanks :-))
I spend my whole day trying to do the (I thought it was...) simple thing:
WPF window, with one button and one label. when you press button, select file dialog opens, and the selected path, if any, is shown in label
After a lot of reading, I think that the "easiest" solution is to use MvvmDialogs along with LightMvvm framework
so that's my first question if someone can help me: do you think it is a good idea?
 
@Markus York, Pennsylvania, USA
We're headed for 3-6 inches :-/
depending on when it switches to sleet/freezing rain
 
@grandangelo i'd recommend Ooki dialogs for file browser
a framework is really overkill for such a simple request
i'd recommend you not use any frameworks for your first couple wpf projects
 
3:35 PM
yeah that was what I was thinking, but everywhere I look at MVVM WPF dialogs, it seems to me that I need around 100 SLOC for something that could be done in three rows in code behind
am I missing something or that is really the case?
 
@Zarenor, basing on default style worked!
 
mvvm requires a bit of setup to get going
 
I've only theoretical knowledge of MVVM - WPF (online training of some hours) and I could really be missing something
 
the advantages aren't realized within such a small scope
if that is the full scope of your app, theres not a real reason to use mvvm
 
App will grow with time, I'm building a system to build distribution kit of test systems for avionic components
but I need to start from simple
and I want to learn WPF, more than the few I know about windows form
 
3:38 PM
the major bit you will need is a view model that implements INPC
that will allow you to databind between your view model and your view, and have your label update with whatever text you want
 
I don't get the acronym sorry
let me google that...
ah ok, that I know :-)
I managed to do the following: bind the view to viewmodel via RelayCommand taken from light mvvm
but now I don't know how to open the system dialog for select file, it can't be the viewmodel
 
Dialogs are always messy
 
@Lynn You should embrace the snow! If you haven't already, buy a rwd car, and have as much fun you can possible have!
 
usually I recommend abstracting them into a service
 
yes they are, and I'm feeling stupid :-)
can you give me some advice where to start from? Googling did not help me, there are too much information and I'm not expert enough to understand what I should take away
(sorry english is not my natural language)
 
3:43 PM
It's only because the imperative style of WinForms made dialogs seem simple (though if you wanted much custom, they weren't)

WPF definitely takes a more abstracted view
 
Hey everyone
 
Generally, for a dialog, we'd write a separate class that handles creating dialogs, so that if you want to change the way those dialogs look (or what implements them!) you have a single place to change them
 
@BradleyDotNET Hey, I did a whole lot of research over context disposing with repos and the unit of work pattern. I was hoping we could continue our conversation from yesterday afternoon. I finally understand the problem completely.
 
And you can manage in the same place what dialogs are available, etc.
We call any time we unify the management of something like this a 'service' in WPF. Services sit outside the MVVM initialism, because they don't deal directly with the interaction between the UI and data - they're kinda 'bolted on'
Otherwise, the way you have this set up - a button on a view (the window, in this case) that commands the ViewModel - sounds exactly correct.
 
@Zarenor you mean I should put dialog in a separated class, and call it when needed? If so, should it be the viewmodel to do so?
 
3:47 PM
If, instead, the command was fetching something from your data backend, that's the 'Model'
 
What if you have an object, and that object have a couple of properties, and a method that will change some of those properties. Should that method return void, or should it return this?
 
Separate from the ViewModel, you want a class that manages any dialogs you plan to create. That way you can, for example, for now use the system dialogs, but perhaps tomorrow use your own, and the next day some frameworks.
 
ok that is clear. and is ok to call these dialogs from ViewModel? Doesn't it imply that the ViewModel knows about the View?
 
You then also make the decision in your DialogService class what the ViewModel needs to do in create a dialog - Does it only need to send a string? You can decide what is needed.
 
@grandangelo, thanks for asking these. I'm in the same boat
 
3:50 PM
No, that's exactly the crux of it! You're understanding! The DialogService knows about the dialogs, but not about the view models. The view models know about the service, but not the dialogs.
The ViewModels call functions on the DialogService (probably async ones) to ask that it creates a dialog and ask for the results.
 
@cudima you're welcome. today I got my salary to NOT understand what I should do...
 
The DialogService knows how to create those dialogs, and return the values, but has no idea why it needs that, only that that's what it's been asked for. Does that make some sense?
 
yes it does.
I thought it was "forbidden" for ViewModel draw something on GUI
 
This way, if the dialogs need to change, you change only the DialogService, and the ViewModel doesn't need to change
 
DialogService is standard WPF or part of some framework?
 
3:52 PM
Right. It's very discouraged. So we call on a service to do it, because the service isn't a ViewModel.
Usually, you implement your own DialogService.
 
ok so summarizing: using command realy to bind View to ViewModel is ok. Then ViewModel should use IDialogService (that I don't know yet...) to draw dialogs and get results
 
Exactly. You can then change out the implementation of the DialogService without breaking the ViewModel - you're not strongly coupled to an implementation.
 
ok clear. Then I'll have to study how the ViewModel should send data to the Model, that f...ng file is selected to be used...
Thank you very much Zarenor, at least now I have a direction to follow
 
The View is always written to some ViewModel, or an interface representing one. It has to know what to display and how. It's job is precisely that. The ViewModel's job is to aggregate the needed data for display from the Model.
Absolutely! Ask all the questions you need. The patterns are complex and nuanced, but they work
 
I'll come back with questions, be sure about it...
it seems to me that WPF and MVVM have really steep learning curve
I need to understand the idea, then the implementation, then do my implementation
and it's really hard
 
3:59 PM
It is pretty steep.
In the channel description, we have some samples
(There's a link)
If anything in them is unclear, let us know, so maybe we can make it more clear
 
ok thanks
 
yes I saw it on upper right corner
I'm leaving, thanks again, enjoy your lives
 
@Selthien yeah sure
Just remember that dialogs are weird :) Your general understanding of MVVM is correct (even services don't typically know about views, but some like dialog and navigation need to)
 
@BradleyDotNET So I found out that MVVM Light only supports singleton injection, so I can't inject a new context for every request. I believe I need to swap to something like Ninject. Either way, the context needs to be disposed in my unit of work. How can I go about configuring it to inject a new context into my unit of work / repo for each using(var UOW = UnitOfWorkFactory.Create())?
 
4:10 PM
Bear in mind that you could use a singleton to manage the contexts.
The factory might be the singleton you need?
 
@Zarenor well the problem is, if I do a call like _UserRepo.AddUser(...) and the call throws an error, every subsequent call to the repo throws the old error
 
did anyone have a reaction to my question?
 
Ah. Uh. Is this an instance method? Or static?
 
instance
 
Is failure to change to object possible?
 
4:12 PM
"no" - not unless there is some system exception or such
 
If it's fallible, I'd return bool. If it's private or protected, I'd return void, if it's public, I'd probably return this. And there are reasons for those answers
non-api-surface methods probably don't need to return the reference, and are unlikely to be chained or called in LINQ methods like .Select
They're just implementation details, is what I'm saying.
 
this happens to be a public method
 
But "public" API surface is likely to be used in that context, and you can always ignore the return. C# isn't affinely typed, so it's not like the method consumes the object
 
I was kind of thinking that a method in some way should have no side effects... and if you do for example var newFoo = myFoo.Change(); then that will "change" myFoo
 
Does my answer make sense?
 
4:17 PM
but that might just be silly?
 
It's nice if you can have that property, but that requires making a copy of the object
 
When do you use immutable classes vs ones with getters + setters? I've got a class where the necessary props are passed in on the c'tor and there are private, readonly members. I noticed that a lot of the built in MS classes have public setters on props
 
If it's small, and can be though of as a value (not an object), then you might consider making it a struct, in which case that's basically what you will want to do (and what happens)
My ViewModels are typically big, mutable messes to back the UI. Outside of that, I tend to create objects and structs that are immutable and constructed once.
I think it depends on the purpose
I have some 'Managers' in what I've got built, that function as components of the Model, and they are big and internally-mutable, but they don't expose mutable properties, you have to use their methods to mutate them.
 
Been going w/ immutables mostly now. Reading how they're "better": yegor256.com/2014/06/09/objects-should-be-immutable.html
 
Though it's worth mentioning that you pay the same cost either way. Properties are still possibly-dynamically-dispatched instance methods.
I definitely prefer immutable - it's harder to corrupt state with multithreadedness
Aaand that's a lot of his points. Heh. Yeah, exactly.
 
4:23 PM
This has the above link + a nice list from that same article of why immutable is the way to go: stackoverflow.com/a/24134192/177416
 
The only problem is if you create a bunch of them with some tight loop or something. That can cause a lot of GC pressure.
 
Hmm. Why is that?
 
Hm? Trash objects have to be collected. If you have state that changes in a tight loop, each mutation requires a new copy, and the old copy becomes worthless
And you either have properly not referenced it, and it has to be collected, or you haven't, and you leak the memory until you free the reference.
 
well gotto go... bye
 
Later, Markus
But that situation is fairly rare. I just know from experience XD
 
4:28 PM
@Markus See ya bud
 
So uh. Anyone got some pointers for me xD
I posted a question over it maybe it could give you guys some more details over my implementation stackoverflow.com/questions/53323562/…
 
Oh, the repo thing. Uh..... I don't know.
 
Whelp. I guess its a waiting game at this point
 
4:55 PM
Should object instantiation include arg validation in the c'tor?
 
There's... debate about that. Old-C# says yes, and throw if invalid.
New-C# says don't have public, fallible c'tors. have public factory methods that have a known failure return (null? tuple of (bool, Type)? Your choice)
 
Throwing in the ctor is problematic.
 
At least, that's what I've been reading lately
 
Most code is not expecting that to except.
 
Thinking that too
 
4:59 PM
Yeah. I've had problems with BCL objects that do that
 
Ideally, you break the work out into an init.
 
It is the way they used to do things, but I think they're trying to avoid it now.
 
I have this app that processes medical reports from text files, currently I extract all the reports (each is stored in a report object) from the text files and store them into a list for processing. I ran into a problem processing to many where I exceed the computer available memory
 
I try-catch business objects that I instantiate, because I'm usually passing in an ID that is going to be the pri key for a db.... and that ctor loads them
 
With C#8, I think you'll be able to declare factory methods with Type? and make everything nice and compiler-warned.
 
5:00 PM
which of course can all fail
But, would you expect a SerialPort class to except in the ctor?
I wouldn't....
afk
 
which approach would you suggest to alleviate this? 1) instead of storing the report string in the object, store the location of the report on disk (file and location in file) and open it when needed
2) convert the report into something that takes a smaller footprint in memory than string
3) some other approach I don't know about
 
I probably ouldn't expect that, but I would expect it to at connect time.. Which might be in the same line, if I'm using( new SerialPort(portId)){*/.../*}
Or something like that
It depends how huge the reports typically are.
If they're not thousands of lines long, I'd keep them in memory. They're probably at most a few MB
 
each is about 50k...not big
 
plaintext isn't big
Yeah. I'd keep them in memory, or at least take option 1, if you can afford the time to load them each time
 
yeah but I tried storing 500,000 of them in memory and total file size was 1.5GB and I exceeded the avail memory
 
5:04 PM
(because they're not huge, it shouldn't take long)
Ah, you're storing half-a-million
 
yeah
 
You can, if you want to get creative, make some sort of collection that handles this caching.
Keep the last (X) in an array, and keep the paths of the other ones.
 
but what if I needed to randomize the entire collection at once? or do some other operation that required them all to be present?
 
Then you maintain a list of whether they're loaded or not, with their index into the array if they are (and some other value if they're not loaded)
You shouldn't need all 500k of them at once.
not the entirety of the whole thing
 
so randomize in chunks?
 
5:06 PM
X can be a 'large' number
For random ones, random ints will work fine
What I'm proposing is this:
1) Array of cached, recently-loaded reports in memory
2) List of file paths or whatevr identifies them to be loaded
3) List of ints of the same length as (2), where the value is negative if the file is not currently loaded, an dis the index in the Array it's found at if it is loaded
 
just to clarify - one operation the user can do is scan the files for reports, then extract a random set of user specified number from the collection
 
Right. That's fine. If the user actually loads all these files, there's not much you can do. If the UI needs all of them at once, you have to have the memory. Or do something complex to know which are actually needed and which are in background tabs (for example)
But this caching from disk collection only maintains X in memory. When one is replaced in the Array, if it's not referenced anywhere else, it's garbage collected.
And it allows quick re-opening of files recently used.
 
iso this is processing in batches?
 
It's a reasonable solution if you (for example) read only a subset of lines from a report at a time into the UI
 
the reports aren't displayed....the app simply is for processing
the only thing displayed is the files selected to scan for reports
and the settings and other operation etc
 
5:11 PM
Then if you process the thing repeatedly. If you don't, then no. You will want batching , which will be a somewhat different thing
(Though this cache may still help with that, if a report is selected across multiple batches)
 
someone else suggested storing the report text as something else like bytes instead of string because string takes up more memory
 
That's... complicated.
 
sounds like it would be
 
If the text is representable in UTF-8, then it's possible you could encode to UTF-8 and save memory
because Strings are in UTF-16 (as most windows strings are)
Well, they're in UTF-16-ish, or in unchecked 8-byte encoding. It's subtle and complicated for legacy Windows reasons.
 
I think all our text is in utf-8, I've never encountered anything that required UTF-16
 
5:15 PM
You could try encoding down to UTF-8, but it might fail, and you won't have normal string processing without converting it back to String
So you'd still need to convert back whenever you need it in String.
It would save space if successful, though.
 
interesting, I could try that...but I'll still modify the processing to do it in X number at a time...I think that makes more sense
 
I think batching is more likely to be a good idea. Keeping a list of what reports are available, and selecting the subset to be loaded seems reasonable. If there's more you need from the files you can read them one or a few at a time
Though, of course, you could also work to combine these ideas. but that's for you to figure out.
 
what about compressing each string using zip?
it might slow things down though to have to decompress and compress when I need a report
nevermind I think its a bad idea and will just slow things down
 
Yeah, that's a pretty expensive operation. It would probably work, but be quite slow.
 
5:35 PM
@Selthien Sorry I didn't respond earlier, had to take care of something. Dealing with singleton injection is why I suggested the cache
Do you still not understand that?
 
@BradleyDotNET Well I prefer to try and not use a cache. I am thinking of switching to ninject so I can use other types of injection.
@BradleyDotNET seems like no matter what I do though even with ninject I cant quite get the context to do what I want
 
Well it probably is more flexible. The problem is without some heavy use of the container itself I don't think its going to solve your problem
what's wrong with the idea of a "context cache" in your mind?
 
I guess what I am trying to figure out, is how to use the same context within my unit of work/factory/repositories. I am playing with ninject and it seems as though it is injecting two separate contexts, one into my factory and one into my repository
 
Right. That's the problem I am referring to (if you don't make it a singleton)
 
Well I want the context to be disposed as soon as possible. I prefer not to cache it for such a long time
 
5:40 PM
You can't have your cake and eat it too without explicitly creating a scope with the container, and even then you would need freshly injected repos (yuck)
previously it had application lifetime, but I can see why you would want it shorter
but even then, my cache/factory does exactly what you want
you just need an extra method to clean it up without creating a new one
and handle the case where one is asked for while its null
 
could you give me an example of your cache with a context?
Another thing, I commented out my binding for my context injection, yet something is still injecting the context...Confusing the heck out of me. Maybe I am injecting incorrectly, I don't actually have an interface for the context
 
Just like before with the UoW factory, you have a factory for your context, except it holds the last instance that was created
and users can ask for the last one instead of creating a new one
 
0
Q: HLSL circular/spiral transition shader

MikeI am developing some shaders for WPF, and so far I managed to get fadeout, and swipe shader working, but for this one, I have no idea where to start. Could someone please hand me out a few tips on how to approach this problem? What I am trying to achieve is the following: Thank you

 
Hm.. I think im having trouble following that
 
5:59 PM
which part?
UoW tells the cache/factory to create a new one, repos ask for the current one
 
Yeah I guess I would just need to change my repos to take the ContextFactory instead of the context.
 
right
I just don't see how you'll get the lifetime control you want otherwise
 
Factory methods are just a little new to me.
 
They're a useful pattern, but only used in a few niches. This seems like a good place for them, though.
I'd probably even add another layer of complication to be sure I never need to worry about forgetting to dispose a context or disposing one too early with some wrapping and reference counting, but I'm sure there's no need.
 
6:20 PM
Agreed, factory is easily one of the most overused patterns
Selthien just happened to hit the two places one actually makes sense...
 
yay me lol
Okay I got your suggestion to work. There is one slight problem still. I try and add a new entity, catch the unique key exception, go to add a new one, and when it is added the id seems to have counted up anyway even though I rolled the transaction back?
So I am getting jumps in my auto increment ID like 144 to 151
 
No idea how SQL handles those
but the Id shouldn't be data, so why is that a problem?
Mine jump around all the time
usually for no reason at all :)
 
lol idk just kind of annoying i guess
 
I'd give up on that being annoying in a heartbeat
Just make your Ids GUIDs, then they won't be sequential at all!
 
6:36 PM
^^^
 
Yeah I guess it dont matter lol
 
(also, GUIDs have less possibility of collision for truly insane record counts)
 
But thanks for explaining the whole factory / cache thing. Took care of my problem nicely.
 
but that's not an issue for 99.9% of DBs
glad to help
*help
can't type today
 
Well with your help I learned how factories can be used, better understanding of DI/Repos, and database transactions / context scopes. You have no idea how much this has opened my eyes lol
 
6:53 PM
That tends to happen a decent amount around here :D
 

« first day (2218 days earlier)      last day (1931 days later) »