« first day (2219 days earlier)      last day (1930 days later) » 

9:38 AM
good morning guys, Andrea from Italy here
 
morning Andrea
 
I've a general question about MVVM and dialogs, and I'm going nowhere just googling
yesterday here on chat you gave me advice of using IDialogService
I thought it was part of WPF "standard library", but I need to implement something on my own
my first need is very simple, just need to show the "standard" select file dialog, and get back the path
everywhere I look, I see requests for additional frameworks, and hundreds of SLOC
I don't understand what is complicated about showing a dialog and getting the path, can you please point me somewhere?
 
believe me, I spent one hour looking at you examples, for relay command and DI, and I did not realize there was one sample with open file dialog... ok thanks I'll take a look immediately
 
@Mav @Johan and others that have contributed, great work with the samples!
 
9:53 AM
yeah, they are awesome
 
and despite all of your work, there is always some newby asking for clarifications already clarified :-)
 
 
2 hours later…
11:27 AM
@grandangelo never hesitate to ask
chat is allowed in chat :D
 
thank you sir, I'm "studying" open dialog example, will come later after my homeworks :-)
it's a chat, not free consulting service
 
11:56 AM
Hi all
 
Hey Alex :)
good god i have to read from Wed 12:19pm >.<
this is going to take a while!
 
12:12 PM
@grandangelo asking is still free and the more specific the question is the higher the chance someone can answer.
So ask & wait is a good strategy.
 
Hey Maverik
 
And become part of community while waiting.
 
Hey Johan
 
Hi guys
I have seen BinaryReader class available in .net framework
in that class there are so many methods marked as virtual
why is that so?
How do they decide when to make methods virtual and when not to?
 
12:19 PM
Always default to not virtual
I.e. the language defaults
Making things virtual requires careful design.
 
What are those designing decisions and how does it impact the design?
Could you please tell me litlle bit
 
there should be blogs about it, lippert has probably written on this topic
 
how do you decide in case of virtual or non virtual?
 
I use not virtual as a default
I don't have time to write, try a search for lippert and virtual
java has virtual as default iirc
 
User, take a look here for Lippert's explanations: ericlippert.com/2011/03/17/…
 
12:24 PM
:thumbsup: lippert is good
 
Thanks Alex and Johan :)
 
You're welcome. Johan knew the resource to point you to
 
Reed, Lippert & Skeet are safe reads.
@User it is a good question and a broad topic
If you are a beginner you should probably not get stuck on it
Just default to not virtual and use virtual when there is an actual need.
 
@JohanLarsson Johan who is Reed? Does he run a blog? I read several times Lippert and Skeet, and they are really interesting, but never heard about Reed...
 
12:38 PM
^ our resident superstar
 
He's an F# superstar too
 
ah ok thanks for the link
 
I remember I read somewhere here on SO something like "the answer is right because Jon Skeet says it is"... It's like Chuck Norris for software development :-)
 
Yup
He's over a million rep points on SO
 
12:45 PM
one question about OpenFileDialog example (https://gitlab.com/so-wpf/samples/OpenFileDialog/tree/master): if i put a breakpoint in GetFileCommand.cs, line 22
var vm = (MainWindowViewModel) parameter;
I see that "parameter" variable is of type "MainWindowViewModel". I don't understand where this parameter is passed, trying to do on my own I always get a null
Is that "CommandParameter="{Binding}" in xaml isn't it? Just realized I was missing it.
 
1:32 PM
I think so, without looking at the code. That would makes sense to me. Though I'd probably make it a conditional assignment, personally.
 
I don't understand sorry. Do you mean doing it in View code behind?
 
1:51 PM
No. I mean where you have var vm = (MainWindowViewModel) parameter;
I would have if(parameter is MainWindowViewModel vm) {*/ etc. */}
While your view should always pass that correctly with the correct type, the is cast ensures you won't throw an NRE if something else (including maybe your view) doesn't pass the correct parameter
 
ok clear. If I'm getting it right, the conditional behavior you ask for is assured in the example by the CanExecute method.
public bool CanExecute(object parameter) => parameter is MainWindowViewModel;
 
Ah. Yup, that looks like it will do it.
 
 
1 hour later…
3:11 PM
finally caught up on the transcript.. @grandangelo just want to give a special shout to you for your positive attitude towards learning.. so many people come here asking questions but rarely people acknowledge that we take time out of our jobs so value our time and not use us as a consulting service & "let me google" - you're welcome to ask questions here :)
 
Mav's alive!
I totally concur btw. Also want to add that passing your whole VM as a command parameter is a decent sized red flag
 
sorry i was out of city yesterday and it's just constant manic here as i have three other channels to track for job :D
lol i did add disclaimer in there for that - Sample quality shit!
 
Maverik, Bradley, thank you. Usually it's me to be bothered with questions that one could answer on himself :-)
 
You're right on track. Keep it up.
=>afk
 
you're welcome Andrea :)
side note: even if it seems like we're not around.. most of us catch up on entire transcripts as and when we can.. you can be sure at least one of us has looked over the content as we start talking about stuff. We also pick up after each others conversations in fluent manner so address questions to channel unless you need a specific persons attention
as Lynn puts it.. we're truly async.. there's no guarantee of response coming back on originating context unless you explicitly request it :)
 
3:27 PM
Bradley, about not passing the whole VM, what is the preferred way?
let's suppose I just want to update the content of a label, how should I proceed?
 
3:46 PM
you can make a child vm that you can pass into command as a parameter just for the purpose and have the same bind to label to display info
but if its trivial enough like in sample, i'd just take the practical route and pass the vm around (parameter isn't the only way of doing this, it can also be done via constructor of command for example when main vm is building command)
 
what's the gain with it? less memory involved? race conditions less likely?
 
Seperation of concerns
 
well its more .. ^
encapsulation.. command doesn't need to know about any of the other stuff.. this is more at the best practice level rather than it right or wrong
 
If the goal of the command is to update a label, I'd typically pass the VM in on the constructor (as an interface of course) and not bother with the command parameter
The interface also works with the parameter of course... but I just don't see a benefit (and you have to have the {Binding} syntax which is just awkward when its the whole VM)
 
at the moment I've a "GetFilePathOpenDialogService" that is the concrete implementation of "IGetFilePathService" interface. Its sole role is show a FileSelection popup dialog.
I have a concrete ICommand object, that takes into its constructor IGetFilePathService.
In the Execute method of the Command, I obtain the ViewModel related to my only view via the "parameter" parameter. This parameter is granted to be populated due to the aforementioned "CommandParameter="{Binding}"" clause in XAML.
Are you suggesting me that I should remove the CommandParameter from XAML, and pass the VM to the Command constructor?
 
4:02 PM
In general, you want to limit the scope of the variable passed to the smallest necessary unit.
Commands would live on the child viewmodel for the view that they correspond to, not in the mainviewmodel.
So - as Bradley said, you can then pass that child vm, rather than the much wider-scoped mainvm.
 
For me, I'd do that kind of thing in the constructor (the command depends on the VM/VM interface)
but its not a huge deal either way
 
Ok... if you have facebook...
 
sorry I'm not understanding...
My View is just a stupid button, with a label. When I press the button, I show a dialog, via a GetFilePathService, invoked by a Command, that is able to update the View because it has a reference to the complete ViewModel.
Do I have to subclass my MainViewModel, with a "smaller" View and related ViewModel?
 
watch this crash video
as your application grows, and you implement multiple views
For now, it's fine the way it is
 
yes I agree I've to keep it simple, I'm already having a hard time to get something working :-)
I really want to learn MVVM correctly, but I spent two days just for showing a dialog and update a label :-D
thank yo uso much guys and enjoy your weekend, I'm leaving soon for my family
btw, where are you from?
 
4:20 PM
Eastern USA (pennsylvania)
and you?
 
"subclass" is not the word you want there
 
4:53 PM
Lynn: she's Andrea from Italy as per her greeting :D
 
5:18 PM
has anyone here used nuget to host their own package feed?
 
5:32 PM
nuget.server @ nuget.org
 
yeah I know, just wanted some feedback on how you like it
I had a project in one solution and now another solution in a different collection of TFS needs to reference that project...instead of moving the project to the other collection/solution...I was thinking to host it on a local nuget server isntead
 
yea thats exactly what nuget.server is for and yea that's what I'd do (assuming a local folder "feed" isn't enough)
 
 
1 hour later…
6:55 PM
erot, The folder feed is usually good enough
alternatively, you can use VSTS to host your feed
super convenient and free for 5 or fewer users
 
I just tried nuget server, its pretty easy to set up
I found a tool that makes it easy to create and publish packages github.com/NuGetPackageExplorer/NuGetPackageExplorer
 
7:56 PM
not just nuget pack/publish?
That is actually pretty easy
I mean, ok, if you really need a UI for that :)
 
8:25 PM
@Maverik I'm a "he", Andrea is male name in Italy :-)
Hope you will answer me nevertheless
(Or nonetheless?)
 
lol, none of us are concerned about that :)
and since you are here... "subclass" usually means "derived class". Nothing should be deriving from any view model usually
I'm sure there's some use case where that makes sense... but its not what you were referring to
 
8:49 PM
Ok thanks, I'll come to discuss this later when I have a deeper understanding of the theme
I exactly meant derive with subclass, asking myself why and how
Going away, goodnight
 
9:03 PM
do you guys know how to bind text to a flowdocumentreader?
 
my first wpf project used it
was a long time ago though
 
well, I can only say "good luck"
I attempted once, but in the end I've given up
 
wasn't sure between setting DOcument={Binding....or creating paragraph, run, etc inside and binding text to the run
 
(changed my requirements instead)
ah, yes, you can definitely bind to a document
it's just creating the document itself is annoying
 
                <FlowDocumentReader x:Name="textBox" Margin="10,10,0,10" Grid.Column="0" FontFamily="Microsoft Sans Serif"  HorizontalAlignment="Left"  >
                    <FlowDocument>
                        <Paragraph>
                            <Run Text="{Binding allText}"></Run>
                        </Paragraph>
                    </FlowDocument>
                </FlowDocumentReader>
 
9:13 PM
i was making a chat thing, and i think i made every message a new paragraph
cant really remember though
it was not trivial
 
yeah its a pain
 
why do you need a flow doc reader?
 
well I don't, I just need to load text on screen and allow user to highlight sections of it using mouse
but I already used it and its working, just need to make a minor change
and I happen to like flow doc reader, you can have different views, zoom in out, search etc
it also doesn't block UI when loading large docs, loads the text async
 
yeah it has some fancy stuff
i was just going to suggest that an items control with textblocks might work fine
up to you to decide what is more appropriate for your use case
one of the pain points for the flow doc that i never solved is you cant select text from multiple runs in one drag operation
 
another thing that's hard is converting absolute char position to the position inside the flow doc
everytime you introduce some formatting, the char offsets get messed up even more
 
9:28 PM
yeah i remember that too
 
what is a good way to trigger a method to run on the view?
 
messenger
 
I remember something called aggregate event?
 
mvvmlight has a messenger implementation if you are using that
 
sorry event aggregator pattern
 
9:30 PM
mav linked a standalone nuget for it a few days ago
 
no not using that one
what about Rc reactive extensions
 
How exactly does that make the issue any better?
 
do you mean a standalone huget for just the messenger part?
 
yes
 
whats wrong with the VM just raising an event the view subscribes to?
the view should know its view model...
 
9:31 PM
its like this...open command -> loads file in VM -> vm sets text in flowdoc reader
 
sure, you could do that without any libs
 
however I need to run a method to highlight the text in the flow doc
this method is located in some other class and it takes the flowdocument as a parameter
the method could be located in the code behind of the view..but I still need someway to trigger it when the text gets loaded
hey wait,...could I just use the textchanged event in the view?
 
probably?
 
9:47 PM
yeah it works but I had to change to a richtextbox instead...flowdocreader didn't have textchanged event
 
 
1 hour later…
10:49 PM
@BradleyDotNET You there?
 
quick ef question, if you have a minute
 
Fun with flexboxes and angular template outlets
sure
 
ah, html
 
pretty much my stock and trade any more
 
10:50 PM
ok - if I use get a DbConnection via CurrentContext.Database.GetDbConnection() ...
then use it and dispose()
it seems I can never do that again.
...am I right?
If I try it again, the func works, but when I call open, I get an error about connection string not set up
Wondering if you ran into this at all
 
never actually done that
 
but that breaking things horribly sounds reasonable
 
hmmm.
The answer seems to be ---
don't call dispose on the conn you get
You can open and close it -- but don't dispose it
Or you never can get another
I think this is me:
1
A: ef core sqlconnection tryopen nullreferenceexception

herme 0So this happens because I was disposing a connection retrieved from context.Database.GetDbConnection(). I created polyfills for SqlQuery and ExecuteCommand which needed a connection string. So once one of them was called I will lose the current context's connection.

anyway, I'm heading out for the weekend; thanks for your time :)
 
11:13 PM
no problem, have a good one
 

« first day (2219 days earlier)      last day (1930 days later) »