« first day (682 days earlier)      last day (3467 days later) » 
06:00 - 16:0017:00 - 00:00

6:31 AM
Hi
 
o/
 
6:47 AM
I have a MyMenuItem with ItemsSource bound to a collection of strings. I want to set up a Command binding for every MenuItem in MyMenuItem. I guess I should edit DataTemplate, but I can't come up with a proper syntax.
@furier Are you capable of helping? :)
 
maybe, sec
could you supply me a gist?
 
I probably found a solution using Styles.
I will say if it works.
 
I have no idea how you would bind commands via styling...
 
<MenuItem.ItemContainerStyle>
                        <Style TargetType="MenuItem">
                            <Setter Property="Command" Value="{Binding ...}"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
Well...
<MenuItem Header="_Select System" ItemsSource="{Binding Systems}">
  <!--I need to set Command Bindings for all Items.-->
</MenuItem>

public ObservableCollection<string> Systems { get; set; }
I guess, I can't do it like that, because I bind ItemsSource to a collection of strings. This way DataContext for all inner MenuItems will be a string from ObservableCollection<string> Systems.
Which can't have any Command.
So I need to create a class-ViewModel to describe System. Inside I shall provide a Name of a System and a Command...
 
7:05 AM
okay you should set an item template and bind up the command to an element there i think
or did your solution work?
 
No. Because I bind to a collection of strings. And each string become a DataContext for each MenuItem.
 
could you paste your code into a gist? gist.github.com
 
Also, editing Template like that means putting something in template, but I do not know what do I put in Template to have a Command property, while saving the look of MenuItem.
Well, I feel like this is one of the times, when I do not know what exactly I want to ask. Like there are few problems I see in here. So, probably, I shall dig more on my own. So do not bother answering, unless you understood what I want to do. :)
 
7:21 AM
I will check.
 
7:32 AM
Well, setting parent DataContext in Resources can be the way to go.
Anyway, thanks for help. You probably gave me the right direction. :)
 
your welcome hehe :P sorry I wasnt much of a help
Busy over here and Iv had a break with WPF, just started again and feel like im totally fresh again :P
 
8:03 AM
:)
 
good morning all
 
Hi.
 
I've a little issue about a DataGrid. I've used one in my project and I've set the IsEnabled property of first and last row to false. I see that it works because first and last row of the grid are grey and cell not editable...
but if I edit the row before the last one, then press Enter and then digit a number, it changes the last row cell
the strange thing is that the edit takes only one digit...
 
8:57 AM
Daheck, my UI ain't being updated on collection change.
Fuk, fuk, fuk!
I create an instance of ObservableCollection in ViewModel constructor. And my UI represents it. But later when I change the collection on button click or whatever, UI does not get updated.
I have two way binding and all required INPC stuff. Using Fody actually.
With changing collection I mean adding new items to it.
 
9:14 AM
Denver, you must check well how you have implemented INPC and Data binding
place a breakpoint into the setter and have a look if value changes...
 
Value does change.
 
check about collection
 
After few method calls my Collection contains 15 elements, while UI displays only 2.
Those 2 elements are being added in constructor.
I use Fody.PropertyChanged
Well, might try to implement it on my own.
I miss something.
 
Surely denver
maybe if you post some code it is easier to help you
 
Will do.
Creating demo app to test.
 
9:26 AM
great job
:)
 
9:40 AM
Now it works in demo.
While I believe I just made all the same.
While I know I did not.
 
10:01 AM
Okay... I found the problem.
 
great!
where it was?
 
I have a Command to add an element in the collection. If I bind this command to a Button, it works fine.
But I was trying to bind this Command in a Style for MenuItems.
I have a method, which is called from the Command. It adds an element in collection.
When I bind Command to Button, an item is added and UI gets updated.
When I bind Command to MenuItem, like in the link above, method is called, an item is added but UI does not get updated.
Dafuq?
Nonsense.
Oh lol, I understood it.
I am creating new instance of ViewModel.
With the syntax.
Crap, me dumb.
 
11:04 AM
How to link Child's DataContext to Parent's DataContext?
I see you, Maverik...
Hi.
 
11:21 AM
Morning
err afternoon now even :)
Child should inherit the datacontext and thus should be linked by default
 
Not like that.
<MenuItem Header="Woo" ItemsSource="{Binding Items}"/>
DataContext for every inner MenuItems will be an element in Items collection.
 
umm yea that'll be the case
you could use RelativeSource ancestortype
level=1
 
wow
 
?
 
Wish you were close to me.
 
11:26 AM
though I don't like using x:Name .. you could use that and use ElementName binding instead too
lol
 
closer*
:)
 
also you realise that you'll need to do this via an implicit style since you won't have access to generated items
 
<MenuItem.ItemContainerStyle>
    <Style TargetType="MenuItem">
        <Setter Property="Command" Value="{Binding ????}"/>
    </Style>
</MenuItem.ItemContainerStyle>
Like that?
And now I need a proper syntax for ????
 
yea that should work
lol
i'll need to see whats going on in VM of that command
 
It just adds an item in collection.
 
11:31 AM
yes but obviously there's some VM in collection that's being rendered by menuitem
whats the structure?
i can't give you a blind binding now can i?
 
I mean, how do I get parent MenuItem DataContext with this syntax.
I do not need the exact thing.
Well, okay, gimme sec.
 
"{Binding RelativeSource={RelativeSource AncestorType=MenuItem, Level=1} Path=DataContext}"
Level=1 may not work, fiddle with the number until it does - its just an optimisation to limit how up the chain binding will travel before giving up
i prefer to limit that because its easier to debug a wrong binding like this rather than it finding an element that matches but i wasn't actually expecting that match
(you could remote limit=1 completely in first go to be sure it works)
 
You can skip first file if you are going to look at app, it is just default ICommand implementation.
And now I am reading your answer. :)
 
in terms of pattern: when you are using ObservableCollection, don't have a setter on it
it should be a readonly variable that gets initialised from constructor once
 
Yeah, of course.
I was just hurrying with the sample. But thanks for pointing it.
 
11:38 AM
np
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType=MenuItem, AncestorLevel=1} Path=DataContext.AddItemCommand}"/>
again I'm not sure of the level bit (will need snoop to see how many levels are involved)
just realised its AncestorLevel not just level
I really should do this in VS!!
 
It wooorks, yay!
Maverik, you're da best, youda, youdabest.
I suggest you to change your job and come here in Russia.
I will play PW with you then.
:D
And it works without setting AncestorLevel.
 
of course it works without AncestorLevel
 
Ah, it is for optimization.
1 works.
And 100 does not work.
And 2 does not work.
 
yea stick with 1
 
And is it common way to do such DataContext redirections?
Or does using it mean that I am doing something wrong?
In term of common programming styles.
 
11:53 AM
i dont normally do this sort of redirections but if that's how your thing works then.. well thats how it works :)
 
12:03 PM
Now I need to define CommandParameters with this thing.
Onwards!
 
hi Maverik!
 
Hi!
Okay, Maverik makes me lazy google-wise, so I ask, how can I bind MenuItem's CommandParameter to MenuItem's Header property?
Could it be something about binding to RelativeSource Self...
 
Skills: actually practical skills <-- applicants words
Hi Francesco
same way we did datacontext
instead of ancestor you can use Self as the target
 
Yes, that is what I did.
 
yea i read after writing :P
stream processing!
no look ahead buffer here ;)
 
12:15 PM
That is good, Maverik, always do like that.
I am an acolyte of such approach of reading.
Praise be!
Now I need to understand why I wanted to use CommandParameter.
Probably Maverik can answer this too.
 
so you can figure out which menu item you're processing since your command itself is common to all of them
 
I knew it!
 
Guys sorry for disturb...to validate a cell into a datagrid, is it good to use ValidationRules property?
 
@FrancescoDS Dude, do not you see we have an intellectual discussion going on here! Why do you interrupt?!
 
I'm so sorry Denver :(
 
12:22 PM
You oughtta ping Maverik, Francesco.
I did not say that.
 
morning all
 
Hello, DPP!
 
12:37 PM
Hello all
 
hi sean
 
Hello, Sean!
 
Word, homies
 
MS?
Can I create an instance of public ObservableCollection<string> Col {get;}?
Or do I have to provide it with a field and initialize the field in constructor?
 
Yes. The first one.
 
12:47 PM
But it says I can't, cause it has not setter.
Hello, Billdr!
 
Hapy Labor Day!
 
Change to readonly then
public readonly ObservableCollection<string> Col { get; private set; }
 
readonly is not valid for this item
And Maverik said I shall have no setter for collection.
Just getter. So I guess I have to create a field.
 
1
Q: Is it possible to return a read-only ObservableCollection that the caller can't modify?

AngryHackerConsider the following code: public ObservableCollection<Message> Messages { get { return new ObservableCollection<Message>(); } } Is there anything I can do to prevent the caller code from adding/removing/changing items? EDIT: Sorry, everyone, I just noticed it's a dupe, but the accepted ...

 
private ObservalbleCollection<string> _col = new ObservableCollection<string>();
public ObservableCollection<string> Col {get{return _col;}}
 
I want to use .Add on the collection still.
I just do not want to be able to create new collection.
There was something that allowed to use setter only in constructor.
 
Well that's entirely under your control, no?
 
too serious in here. I'm out. See you tomorrow sirs.
 
:o
ReadOnlyObservableCollection does not have Add method.
 
It does not
 
12:54 PM
So I can't use it.
 
I didn't know that was a requirement, sorry
I didn't read up today
 
private ObservableCollection<string> _systems = new ObservableCollection<string>();
public ObservableCollection<string> Systems { get { return _systems; } }
I will stick to this.
 
{ get; private set; } would do that too
It's just visibility, it doesn't affect the methods you can call
If you have public void Add on something, it will be visible on the property/field if it has an accessible get modifier
 
Well, yes, it is the same.
in terms of pattern: when you are using ObservableCollection, don't have a setter on it. it should be a readonly variable that gets initialised from constructor once

That is what Maverik said.
So I tried to understand how to do it.
And I am too scared to ping Him.
 
I don't use readonly
So....
 
12:59 PM
You don't but also it says that Collection can't have this modifier.
 
Oh right well in that case there is nothing stopping you from modifying it anywhere else
Just make it public get private set
 
1:22 PM
Client: "Hey developer, add this feature!"
Developer: "Done!"
-- Few seconds later --
Client: "It isn't working as we expected"
Developer: "You're right, I got confused in the badly written documentation, check now"
-- Saturday at 21h00 --
Client: "Wtf ? Now it's all messed up"
Developer: "Really ? It seems fine for me, try this"
Client: "Ok, now it seems ok, thanks"
-- Monday --
Client: "Dude, your code doesn't work, look at this well made worksheet with a lot of Pivot Tables and VLOOKUPs"
Developer: "My code is working, try this"
By the way, morning all
 
Morning André
 
1:43 PM
@Sean I feel like you were drunk at this point
yet get; private set; achieves almost the same thing
 
Drunk? No I just don't know C# :D
 
but readonly field is preferred because private set; will not prevent drunkenness
 
When working with OC there's a ReadOnlyOC class
 
good news is, that sort of thing will be valid in c# 6 (or is valid if you happen to be in VS 14 CTP 3)
 
Apparently readonly OC is an anti-pattern
 
1:46 PM
Readonlyoc makes no sense to me
i love the idea of immutable collections but until they give me solid immutable objects.. i can't do much
 
You could just use a OneWay binding
But yeah...
 
hmm no..
 
No?
 
OneWay on collection generally isn't needed because xaml doesn't normally create collection
so you're very much in readonly territory with xaml collections
problem is actually on the objects from collection (in my immutable context)
(especially outside xaml where things can change the object without me realising)
i've read the workaround.. but thats the main issue.. its a workaround for a limitation and its too much work
so i'm gonna wait until they give me immutable class keyword
 
I lost you
At workaround
As I didn't read it....
An immutable keyword would be cool though
 
1:49 PM
well workaround basically says you create a constructor with all properties and then everything is readonly
then if you need to change something, you copy that thing again and change whatever you want in new instance
while technically that will achieve immutability, its just too much boiler plate
 
That seems nasty
 
its easier for me to just remember not to edit stuff
considering they've now given us syntax like public int MyNumber {get;} = 6
 
Ooooooh that's nice
 
and we now have a class level property initializer without constructor -- i think immutable will come soon enough
 
I saw some cool syntactic sugar but I can't remember what it was...
 
1:52 PM
yea its part of c#6 available in vs 14 ctp3 right now
 
I've just started VS2013 with Update 3 installing on my laptop
I heard the CTP doesn't work with VS2013
I should try one of these things out some time
Being on the bleeding edge would be kinda cool
 
CTP3 should
CTP 1 & 2 didn't
(CTPs worked, but they messed up VS 2013 and you needed to repair VS2013 after CTP uninstalls)
 
Well I could spin up a VM
Cos I now have the RAM and processor to do so
AWWWWW YEEEEAH
Technically my laptop is now more powerful than my home PC
It makes me happy and sad at the same time
And I don't need to cos CTP3 works with VS2013
Man I really should engage my brain every now and then
 
2:07 PM
well guys, I've implemented validation for a cell of datagrid
but I have another little issue...
in my datagrid, first and last rows are always disabled
to avoid that user can change their values
the fact is that, if I edit the n-1 row and press enter, and user digits something, the last cell value changes
key down event seems to not manage the enter key...
 
If it's a routed event it's probably been handled by the control itself
Which is a good thing, as it is expected default behaviour
 
why is first / last row doing that?
 
Hey guys
 
hey stranger!
 
because I need that first row has value 0 and last has value 100
 
2:13 PM
Hey Sisyphe, long time no see =]
 
it is a percentage datagrid
 
hmm ok, so how have you implemented that?
I'd just have CanUserAddRow="False"
and have 100 flat rows (i.e. 100 items prefilled in itemssource)
 
yes I have CanUserAddRow = "False"
my itemssource has got all rows
I've added the following
<Style TargetType="DataGridRow">
<Setter Property="IsEnabled" Value="{Binding isEditable}"></Setter>
</Style>
 
hmm not how i would have gone about it
 
Yeap I dont have much time to wander around here anymore :(
 
2:16 PM
if the rows in datagrid, you should be able to edit it
yes we know sir sisyphe
promotions and all that :P
 
nice to see the old ones are stil hanging around :)
 
well i'd say new blood has pretty much taken over now
I'm just a relic of old times now :)
 
well it's not really beacause of that... more beacause I switched to JS
 
I need to have it in datagrid because user must see that he has got two default rows
 
haha
Maverik the relic
sounds neat
 
2:17 PM
and can add or remove rows
 
nope
 
between first and last
 
Item: Maveril (1H Hammer) - Quality: Relic
xD
 
Maveril: a cross between Mav and mithril.
 
:D
even better :)
 
2:17 PM
A shiny indestructible bundle of awesomeness
 
I WANT IT !
 
SOLD! To the man with the promotion!
 
@FrancescoDS if there were 100 flat rows, none of this would be happening!
 
Yay ! :D
 
starts to strip down for new master
 
2:19 PM
We'll just package him up. Delivery should be within 1-2 business days. We would skimp out on the devliery costs but he might not get there alive if we do that and I cba with that paperwork
 
I knew I had to come to this room today :D
 
no? i have to be packaged too?
oh well! guess strip show will have to wait
 
It's one of those stripper cakes
 
well of course
 
@Maverik what do you mean with flat row?
 
2:19 PM
@FrancescoDS no adding removing rows - just have 100 rows
 
How can you be delivered if you are not packaged man !
 
Bit of padding, some internal reinforcement and you're all set to be lobbed unceremoniously onto the back of a UPS truck
 
the way i was delivered originally?
 
packaged in placenta ? :P
 
@Maverik it is not what I need...user must add or remove rows...but first and last are always there without possibility of change
 
2:20 PM
but its ok if you want some frills attached - you're the customer!
 
That would require a big-ass cannon, some red jelly and a whole lot of maths to get the aim right. Sending you in a box is cheaper and easier
 
I do, I most certainly do !
 
@FrancescoDS you have an odd design!
working against nature is never easy
so for this particularly screwed up case, i'll need a short but complete sample to fiddle with
 
And a padded landing assembly at the other end, almost forgot about the landing. It's easier in a delivery room, the midwife just has to stand back and catch
I need a sound delivery system. My baby-popping-out noise is brilliant
 
@Maverik customer asks it...
how can I do the same in other way?
 
2:22 PM
I don't suppose OC has a .Insert method?
 
@FrancescoDS if the customer asked you to fly - will you still comply?
 
Oh it does as well
 
when you agreed to draw transparent red lines, you pretty much agreed to be on your own
however if you can show me transparent red lines, then yea i can help
 
So maybe you could insert the newly added item into your ItemsSource with .Insert on the command? I dunno if that's possible
 
@Maverik no...for sure...but flight and datagrid usage are a little bit different I suppose :ç
 
2:25 PM
but you're not using it as normal datagrid are you?
 
or not...?:P
 
Francesco each time I pop here you seem to have weird use cases :D
 
what you basically need is a title and total row
 
MAv...my fault...I've not explained it clearly...
imagine to have a line. each line has infinite number of positions, but surely it has a position at 0 and one at 100% of its length
that datagrid represents that positions in the line
 
That sounds contrived
Why would you want/need to be able to control the line down to that level?
I don't expect you to re-write now but surely it would be easier to supply transforms to be used on the line then you only need to specify a start and end point and a transform
 
2:29 PM
yea no matter which way you slice this, its just an odd thing to do
 
You know, line.Start = (0, 0); line.End = (100, 100); line.Transform = ArcTranfsorm(30deg); or something
 
reeks of bad design
 
I'm probably blabbing. I have no idea about the actual use case
 
neither do i :D
but it just doesn't sound like the right thing to do
so we have to now somehow force datagrid to do something its not supposed to do
i'd just subclass datagrid and override with code to deal with this thing
there's no easy way to handle something odd like this IMHO
 
Maverik : I have an issue, could you help me ? I need to draw 7 red lines perpendicular to each other with green ink !
 
2:31 PM
xD
that's what i said!
but i want transparent red lines first!
 
Mav...
please...
 
:D
 
yes Francesco, i'm serious - subclass datagrid
and override in code
 
and a line in the shape of a kitty please
very important
 
there's no easy way to do what you're doing because thats not how things normally work
lol you remember that skit well sisyphe
sweet r# 9 is on the horizon finally
 
2:33 PM
It really made me laugh...
 
Does it come with a romantic sunset?
 
what's r#9 ?
 
@FrancescoDS The only way we can help you with this is if we can see code and have an explanation of the use case
 
The only problem that I have with this datagrid is that my last row has the property IsEnabled = false but if I use the Enter key to enter data in previous row...it allows to change the last one too
DataGrid allows to have not editable rows, so you can try with any kind of use case
that expects that one row is not editable
but it is not really ...
 
How does the enter key let you edit the last row? I don't get that
 
2:40 PM
in editing the second last row
 
I genuinely don't get it... If your last row is set to disabled, the only way you could possibly edit the final row is if your index is wrong or your bindings are somehow mucked up... No?
 
in other rows, enter key allows to go in edit mode of next row
 
Huh.... That sounds broken
Surely it shouldn't do that if the next row is disabled
 
so what must I check?
 
I dunno....
Something like checking the enabled/disabled state of the row item on RowEditing and unsetting the focus from the disabled row?
That's a guess, that event might not even exisst
 
3:16 PM
maybe I need to create a question in SO
 
That might be an idea
 
:D
 
I've done this:
private void FixedPositionDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this.FixedPositionDataGrid.CommitEdit();
e.Handled = true;
}
}
In this way, value is commited and edit mode remain on current edited cell
 
06:00 - 16:0017:00 - 00:00

« first day (682 days earlier)      last day (3467 days later) »