« first day (1138 days earlier)      last day (3011 days later) » 

2:38 AM
Figured it out!
 
 
5 hours later…
user4433485
7:34 AM
good morning everyone
 
8:48 AM
Morning kids
 
user4433485
Heya
 
How're you Kat
 
user4433485
Well Good and impatient
 
user4433485
You?
 
Interesting combo, I'm awesome as always
 
user4433485
8:51 AM
:D Good to hear!
 
user4433485
I want to be a lot further with my project! Doing good so far :'D in the meantime a friend of me is selling his car and I really want it.. :'3
 
@Feeds Hmm. Out of the WPF improvements in 4.6.1, the "RichTextBox maxes out the CPU" is one I've ran into several times in the past, and I'm glad it's fixed.
 
user4433485
Oh about richtextbox. if you want to get the content, you can't simple do richtextbox.text right?
 
user4433485
RichTextbox.Document.ContentEnd
 
user4433485
is this right?
 
9:03 AM
TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
return tr.Text;
It offers much richer options, which in turn mean more complicated interfaces.
You can store the TextRange to a Stream, too, as text, RTF or XAML.
 
user4433485
the thing is..
 
user4433485
I store the content into a database
 
user4433485
and I want to show the database on a php web-app
 
So you probably want it as HTML. Which the WPF RTB doesn't natively support.
 
user4433485
And, how am I going to do this?:3
 
9:08 AM
Here's one approach, though I haven't tried it: blogs.u2u.be/diederik/post/2010/08/31/…
Basically, it saves the RTB as XAML, and converts that XAML to HTML.
 
user4433485
ughh
 
user4433485
wish me luck :3
 
G'luck with that. Or maybe try to find a custom 3rd party controls that does HTML natively. The RichTextBox is for RichText (RTF), and not originally designed for HTML.
Now I gotta go.
 
user4433485
9:28 AM
thanks
 
user4433485
10:27 AM
someone with experience with the DataGrid?
 
10:48 AM
I've used it
 
user4433485
I found out how to use it :p
 
user4433485
Was the first time I had to 'fight' with xaml :p
 
user4433485
Oh well table stuff is awful in html as well so
 
user4433485
11:03 AM
Time to get myself a lunch, cya <3
 
user4433485
2:27 PM
ugh trying to get data into a combobox
 
user4433485
not that easy after all
 
user4433485
can someone explain me about DataTable?
 
3:02 PM
what's your issue @Катерина
with combobox that is
 
user4433485
Yeh
 
user4433485
I am trying to get data from my MySql database into a combobox
 
user4433485
stackoverflow.com/questions/8154547/… I am checking this question
 
user4433485
but for some reason, I can't get my combobox working
 
You should consider if you haven't already, not directly connecting to a remote MySQL Database for security reasons. An API is a better way to go
 
user4433485
3:07 PM
meh
 
are you getting the data from the DB already?
 
user4433485
I don't know how to use API's etc
 
(yes you do ^ )
 
user4433485
Well Yes, the database works fine. Can insert stuff
 
user4433485
I am just doing something wrong
 
3:08 PM
okay, so then when you get your objects, what do you do with them?
 
user4433485
?
 
user4433485
 
do you have fillcombo()?
 
user4433485
Well, I was trying to get it working but what on earth is DataCell
 
user4433485
This combobox really.. Frustrating
 
3:30 PM
you aren't having an issue with a combobx
you dont seem to understand WPF binding
 
user4433485
hmm
 
try to populate a combobox with a hardcoded list of strings in a view model before trying to mess with a database
if you can get that working, db will be easy
 
user4433485
mmmm
 
user4433485
Drives me nutz
 
public ObservableCollection<string> ComboBoxItems = new OC<string>() { "one", "two" }
<ComboBox ItemsSource="{Binding ComboBoxItems}" />
 
user4433485
3:33 PM
:S
 
user4433485
I don't get it
 
@Julien good advice, I tried the same when I ran into that issue a few weeks back.
Btw got the data template working and refactored to have an App VM and View. My previous project had used the same approach and didn't remember
Anyone have advice on passing a field from one VM to another when a record is selected in the first view?
 
@Катерина gonna have to be a bit more descriptive. you have a list of items. you have a combobox that is bound to that list of items. the combobox shows what is in the list
@BrianJ if the vm's are decoupled, use an event
 
user4433485
Like an array @jullien?
 
observablecollection = list = array
 
user4433485
3:43 PM
Well I won't try it today, frustration over 9000, not sure if I can do something good right now :)
 
i tried to make a simple asp.net website the other day. i am so terrible at it. i spent like 2 hours trying to make a sidebar menu i could do in wpf in 5 minutes
now that is frustrating
i just gave up
 
user4433485
I've been doing this combobox for 4 hours now :p
 
a working combobox is like...4 lines of code :s
 
user4433485
I cant give up, I just get angry and mad, doing silly stuff.. need to learn how to control my emotions
 
3:47 PM
@Julien any thoughts on using a Messenger class like hastebin.com/yufogexofo.cs to send the data between VM's. Or is an event better?
 
user4433485
I've got so much to learn yet, same for getters and setters, Don't know anything about it :3
 
user4433485
Thanks @Julien, will definitely take a look
 
@BrianJ those messenger classes are just wrappers around an event system
same thing
you 100% should be using something like that
 
ok
It takes away some of the complexity
 
do you use Fody?
i do exactly what you are trying to do in lots of places
 
3:49 PM
?
 
with fody i have methods in my VM like so:
public OnListBoxSelectedItemChanged()
{
   Messenger.Send("SelectedItemChanged", _selectedItem)
}
other VM's that care about that selected item listen for that event and react appropriately
 
ok seems like a good idea, pretty similar to the class I have at the moment in implementation
 
Fody removes the need for backing properties, you don't have to write any INPC code, and you get nice auto methods, like OnMyVariableChanged()
 
ok
That could be useful actually
OnMyVariableChanged()
 
i mean you can already do that with stock wpf, you just have to put all that logic in your property setter
 
3:55 PM
I'll try implementing my Messenger class first and then look into Fody for optimization :)
but it does look like it would save time and make my code cleaner using Fody, will read up on it
 
user4433485
Well, Thanks All :) Good evening and cya tomorow :3
 
INPC code is gross
fody = great
 
 
2 hours later…
6:07 PM
posted on December 01, 2015 by Bertrand Le Roy

This is our first "The Week in .NET" post. Our objective in writing this is to provide more regular updates about what the team and core contributors have been working on, and to give a community heartbeat, in the form of a list of interesting links. Of course, if you wrote a great blog post, or just read one, if you want to show a great new contribution, if you've written a useful library, we'

 
6:59 PM
@BrianJ and @Julien Just as another voice here - I'm actually not a huge fan of messenger systems (or Fody, for that matter ;) )
Messenger systems very easily become a "god class" and turn everything from nicely typed into a big soup of effectively static events
 
say you have a view with a listbox, and another view that depends on the listbox selection. both views have a different VM
how do you pass selected item ?
 
through the VM that "owns" them both
 
isn't that way more gross then a messenger send
 
no
because they're already logically coupled
 
right but whats the actual methodology to pass the value
 
7:05 PM
I'd rather have the code reflect that than have a messenger that relays both that pair as well as every other listbox selection...
 
so you have a public method in your parent VM that accepts a value from wherever and sets that value in a specific VM
 
typically I expose the selected item as an IObservable stream on the child, and have the parent just subscribe/set
 
can you show an example of that?
 
so - it'd be in F# ;)
though you could easily add plumbing for it if you wanted to make things work in C# too
 
i mean the whole point of usiing messenger is to avoid having to do any plumbing
 
7:13 PM
it is plumbing
and you're using Fody to build out plumbing for you, too
you're never eliminating plumbing if you're using INPC anyways...
my INPC implementation already gives me IObservable<T> for free
 
let me rephrase
do as little plumbing as possible
 
so I can just add a property to my VM like member val SelectedItemChanged : IObservable<_> = selectedItem
then the parent VM can do selectionVM.SelectedItemChanged.Subscribe(fun n -> otherVM.Selection <- n)
and I'm done
it's no more code than managing the subscriptions through a messenger service, but it's all type safe, clean, and doesn't require all of the filtering because messengers handle events globally
 
managing the subscriptions is literally subscribing and unsubscribing
that is two lines of code
 
this is too ;)
 
i like your concept, i think i'd have to see a c# implementation
i dont know how to do the observable stuff
 
7:18 PM
but what happens behind the scenes in a messenger service is ugly
 
i am not working with performance demanding applications, simple LOB
 
because there's no type safety, and everything has to be filtered based on subscriber, etc
 
worrying about what is going on behind the scenes is above my pay grade
 
yeah, but the lack of type safety is also a correctness issue
not (just) a perf. issue
 
mvvm light messenger service lets you specify the subscriber and argument type
i thought it was type safe
so does xamarin forms messenger
 
7:20 PM
yes, but internally, there's zero type safety
it's an illusion ;)
nothing will error out if you publish with type Foo and subscribe with type Bar
 
i love upgrading my patterns, but i gotta see this one in the flesh
 
your messages will just "vanish"
 
right. gotcha there
 
which is a maintenance nightmare
because if you refactor one VM, there's nothing that will correct it on the other
hence - it's not really type safe
 
yeah def no compile time checking
 
8:09 PM
Ok that's an interesting point on the above, I'd try to implement that instead if I could get a relevant C# sample to work from
 
8:22 PM
@JohanLarsson Do you have a good INPC to IObservable implementation for C#?
 
8:47 PM
Hey all
got stuck a little bit
I've got a class call AccentColorMenuData that has public members Name, displayName, BorderColorBrush, ColorBrush
and these are all bound to menu items generated at startup
and because it's a different class
I can't bind those contextmenu items to commands defined in my ViewModel class
 
good old context menus
i have a solution for that made by our very own @JohanLarsson i believe
 
I want to bind the command property to commands defined in ViewModel
NOT EACH CLASS OBJECT!
 
How do I implement that into a setter
in a style
 
            <Style TargetType="ListBoxItem">
                <Setter Property="ContextMenu">
                    <Setter.Value>
 
you can open up the value tag and put whatever content you want
doesnt have to be a string like your one liners
see above
 
so I need to set the datacontext to my ViewModel Class rihgt?
in the styleS?
<setter Property="DataContext" Value="{Binding local:ViewModel}"
if ViewModel is the name of my ViewModel class?
I still get the error
System.Windows.Data Error: 40 : BindingExpression path error: 'ChangeAccentCommand' property not found on 'object' ''AccentColorMenuData' (HashCode=8962752)'. BindingExpression:Path=ChangeAccentCommand; DataItem='AccentColorMenuData' (HashCode=8962752); target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand')
the 'object' needs to be 'ViewModel'
 
you shouldnt have to set any data context
 
it's a separate class defined within ViewModel
it's ViewModel.AccentColorMenuData
I want it to go up a step and only look in ViewModel
 
that is what the rootobject does
View -> ViewVm
    MenuItem -> MenuItemVM
    MenuItem -> MenuItemVM
 
9:00 PM
on the 2nd line of the xaml, what is DataContext? Is it a static resource?
 
:s
 
<ContextMenu DataContext="{Binding DataContext, Source={_3RdParty:RootObject}}">
 
DataContext is a property of a view
 
Binding DataContext
 
it holds the data context
 
9:01 PM
so for me it would be ViewModel
 
if you have MainWindow.cs, and MainWindowViewModel.cs
the DataContext of MainWindow is MainWindowViewModel
 
I have mainwindow.cs and viewmodel.cs
 
and you assign the data context somewhere i would figure?
 
behind on initialization
to mainwindow
        InitializeComponent();
        mainCallbacks = new MainWindowCallbacks(this);
        vm = new ViewModel(mainCallbacks);
        this.DataContext = vm;
 
so you are setting the data context of the context menu to the data context of the root object
root object being your window
 
9:02 PM
@ReedCopsey here is some stuff
 
{Binding DataContext, Source={_3RdParty:RootObject}} == {Binding RootObject.DataContext}
 
It is pretty hairy but it handles nested subscriptions
Not sure it is very good but it has decent tests and we have used it a lot
 
@Julien So then my source would be local?
 
see Conversation above my request?
do you have any sample code that'd show him how to do that using your stuff?
 
ok, reading
 
9:04 PM
@JoshMenzel the idea is you dont change that line
your context menu can now call commands on the parent vm
 
@Julien, can you give a short version of what you want to do?
 
you have a view with a listbox and a backing VM holding SelectedItem
then you have a second view with a different VM that needs to know that SelectedItem
pass SelectedItem from vm1 to vm2
 
@Julien it's still looking for the command on the wrong class
<Setter Property="DataContext" Value="{Binding local:ViewModel}"/>
 
? don't do that
 
then how do I tell the menuitem to resolve the command to ViewModel and not the current object instance that is a type of AppThemeMenuData
 
9:08 PM
you use the code i gave you without trying to manually change data contexts
 
It's only the command property that needs to be resolved though
 
@Julien that is helping josh right?
 
I can't change the entire contextmenu
 
@JohanLarsson nope that was what kicked off the discussion with Reed
 
9:10 PM
he has an F# solution that sets up an observable on SelectedItem, and the parent vm monitors vm1 for changes and sets vm2
i advocated for just raising an "ItemSelected" event passing the selected item
 
the views should share a single instance of the vm with the list and selected item imo
compose with viewmodels
 
really? imagine if you had a nested set of listboxes. then you end up with chained view models
 
singleton perhaps the easiest way but nicer to do it usning the container
 
either way, where would I put that rootobject class?
 
@JoshMenzel in your project...anywhere
 
9:13 PM
in the view project
 
and how does that grant AppThemeMenuData access to ViewModel's commands?
 
@Julien you might be interested in the IoC demo here
 
it makes the data context of your context menu be the data context of the item that is holding the context menu
aka "go up a level"
 
probably not a solution for you as it adds quite a bit of style
 
okay...but what if I ONLY want to do that on the command property specificaly?
 
9:15 PM
? why
 
because of the styling and the way the data is stored
 
chances are I did not understand your spec at all
 
there is a name property bound to the instance of AppThemeMenuData
 
you cant change the datacontext of a property
i shouldnt say cant. you probably dont need to.
@JohanLarsson Choose manufacturer -> choose model -> choose year -> choose color
 
9:17 PM
so now ColorsVm has a reference to YearsVm which has a ref to ModelsVm which has a ref ManufacturersVm?
that is gross
 
so then how do I get AccentColorMenuData to access ViewModel's RelayCommands?
 
is ViewModel the root object of your context menu
 
no
AppThemeMenuData is
or are you referring to the structure
 
what is the DataContext of the control that is hosting your context menu
 
ViewModel
 
9:19 PM
is ViewModel the root object of your context menu -> yes
 
but each menu item's datacontext within the contextmenu is AppThemeMenuData
 
so ?
 
that's what needs to change for the command property
I tried binding the command on the contextmenu and it doesn't fire if I click on one of the sub-menu items
it needs to be set as follows:
MenuItem.Icon DataContext = AppThemeMenuData
MenuItem.Name DataContext = AppThemeMenuData
 
right. i think i understand your issue now
 
MenuItem.Command DataContext = ViewModel
 
9:22 PM
you cant have half and half
 
it's looking for a command object within each instance of AppThemeMenuData
 
maybe you could hack it..
i dont have code for this but
you could try setting the Tag of the context menu to your ViewModel
 
which would be fine if I didn't want to have access to viewmodels definitions
 
and then have the Command call your method on the Tag of the context menu
i have done stuff like that before but it gets ugly fast
you might want to consider passing a reference to your ViewModel to your menu items
 
All I want is to be able to access and use viewmodel's functions
from within the appthememenudata class
 
9:26 PM
make viewmodel a singleton
pass a reference to viewmodel into appthememenudata
raise an event
those are the 3 options i see that are relatively simple
that is an entirely different question that wanting to go up a level from a context menu
context menus in wpf are pure bitch
 
so I am learning
why is it so difficult to have a dropdown from a button
in the title bar
 
ive done that before, regular button, left click context menu
should have the code here
 
already done it
I have a helper that does the left click
and finally got it
just added ChangeAccentCommand=this.ChangeAccentCommand,ChangeThemeCommand=this.ChangeTheme‌​Command,
to where it generates each item
in the ViewModel class
and defined RelayCommands as public properties
but that is <explicit> as <explicit> the way these menus work
you'd think it'd be easier
 
hmm. i dunno, i'll paste some code for you, maybe it helps
i gotta go
i havent looked at this in ages
but it is a button that seems to be bound to its own vm and still calling parent cmds
good luck :s
 
thanks julien appreciate it!
 
9:55 PM
-1
Q: Getting binding of transform property from code behind in ItemsControl

pt12lolXaml as below: <ItemsControl x:Class="PowersOf2.Windows10.Views.Controls.Board" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:PowersOf2.Windows10.Views.Controls" xmlns:d="http://sche...

 

« first day (1138 days earlier)      last day (3011 days later) »