« first day (917 days earlier)      last day (3232 days later) » 

5:00 PM
okay I think I understand
just didn't think about it really
 
^^ a problem you should solve :)
 
I would push the user to the user table, then use that to reference the associated records in the main item table
 
Right
 
so I would have a second table, User , then when I do a query I would query the item table by the current user
 
yep
well, by that users Id
 
5:02 PM
but I'm not sure why I should have a separate User table, when I could just query by the user ID in the Item table
 
What would that user Id point to?
 
all records in the Item table with that User Id
 
does a user not have other properties
like a name
 
Okay, but that Id is just a number
 
or password
 
5:04 PM
okay I get you, I was thinking by name, so that all records with that name will be returned. I assume this is bad practice though
 
very bad
duplicate data is to be avoided
 
well it means that your name is repeated everywhere in the table
say now your user wanted to rename himself
you have to update every item row
instead of one user row
 
you aren't even in 1NF with duplicate data
 
lol
we have a few 0NF tables out here that were made like two decades ago
err catalogs
for some of our old clients, that were created by people who didn't understand sql
 
5:06 PM
so I would be better of ordering by the ID
 
always
 
I try to get all my tables to 1NF
I probably get to 2 or 3 occasionally by accident, but I don't worry about it too much
 
ok let me ponder on this before I make another silly comment
 
just so you know, you already have a column that would also move to the User table, Gender
 
yeah you were right Bradley... the getter gets called once when the form loads up, and never again
I am adding to the observable collection though
it handles pushing that CollectionChanged event internally right?
 
5:19 PM
right
the getter should only get called once
 
why not again when the collection changes?
how else would the UI update
 
okay I'll get back to you when I find out a bit more on the solution, cheers
 
the itemscontrol has already "got" the collection
now its just observing it for changes
 
ah
 
Right
 
5:21 PM
so then if you were to say MyObservableColProp = new ObservableCollection()
that would not result in an update?
nor would your collection be GC'ed
 
if you did that after form load
your UI would now be bound to the old list
 
good to know
 
which you no longer have a reference to
 
If you raised PropertyChanged on it though, it would update
 
that explains why List works in my other project then
because when I modify the list the itemscontrol is bound to I call PropertyChanged
 
5:24 PM
i think generally replacing the list with a new one is the wrong approach
clear it and rebuild it
 
I don't thought in my other project
but a List isn't observable
so it must be the propertychanged that facilitates the update
 
if you are using a list against a UI you are just making life hard on yourself :)
 
probably, still a WPF noob
and I have a history of when im not trying to pull my foot out of my mouth, I'm tying my own hands
 
You aren't reassingiong the OC somewhere, right?
 
no
 
5:26 PM
did you try recreating a super simple example in a new uc
 
not yet, I was nomin on some fish
listening to blues traveler
this is the correct OC though right? using System.Collections.ObjectModel.ObservableCollection
 
before I dive into the small test app
cuz im pretty sure I understand the binding aspects of the items control
is it possible that this is a cross threading issue?
the events are generated by the async pattern implementation of the whole Socket Receive deal
not sure if that actually happens on another thread
 
you do not have a working items control anywhere
anything is possible
 
In fact I do
My other projects Items control which is nearly identical to this works fine
 
5:32 PM
Async actually helps with synchronization problems, so I doubt it
 
well then the key is probably the "nearly" part
 
but anything is possible
 
i suggest the test control because based on this discussion, to me anyways, it seems you dont have a firm grasp of binding a collection to an OC
if you are confident that you know how to do that, a test app really isnt necessary
 
well I think that adding a static item to the list and having it show up fine demonstrates the binding is correct
the issue lies in notifying the framework of a change
 
which is done automatically by an OC
 
5:34 PM
Right which means the OC is broken... (unlikely)
 
which you dont use, sucecsfully anyways
 
I changed it to an observable collection
its not a list anymore
 
or you have reassigned it, or otherwise totally f-d something up
 
lol probably
 
right. but you say you have a working ItemsControl
in another project
but it doesnt use OC
 
5:35 PM
that's right
 
that makes your two items controls about as different as possible
one is being manually updated by you
the other should be taken care of automatically
 
well the automagic isn't working for me... I probably did something to it
just don't know what Ic ould have possibly done
 
dude. you could have created a sample items control
 
I add to it just fine
 
in 2 minutes
to prove to yourself that yo u know what you are doing
new usercontrol -> plop on itemscontrol -> assign data context of user control to usercontrol.this -> add OC -> add item to OC
you now have an items control that updates automagically
 
6:02 PM
So, I've got a contextmenu which is bound to an object. That optionally has a childen object, which creates another layer of MenuItems (as a flyout) with the children. I just can't figure out how to access the template of the first layer of MenuItems (I want to set the Command).
<ContextMenu Placement="Top" ItemsSource="{Binding DockedUIElementControlTypeValues}">
    <ItemsControl.ItemTemplate>

        <HierarchicalDataTemplate ItemsSource="{Binding Children}">
            <MenuItem Header="{Binding Description}"
                        ToolTip="{Binding Value}"
                        Command="{Binding DataContext.AddToolbarControlCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                        CommandParameter="{Binding Value}" />
How can I set the template for the MenuItems at the top level?
(Tried DataTemplate; it complains that I'm already setting the template -- because of HierarchicalDataTemplate. )
Which means I can probably modify HierarchicalDataTemplate somehow to include a definition for the top layer.
 
Sorry, I'm still not entirely sure what you are asking
 
It's almost like HierarchicalDataTemplate should have an element that means 'give me access to the current element's template'.
@BradleyDotNET I'll grab a screenshow and throw it in paint.
 
EF does not support dictionaries
:(
 
@BradleyDotNET here comes the pic
 
@Julien Did you expect it to?
not really something that maps well to a table
 
6:11 PM
lol well i asked how best to store this stuff and came out with a Dictionary
so yeah sorta
 
@LynnCrumbling So in your code, the inside of the MenuItem is the sub menu in your picture?
 
Correct -- the MenuItem is the subitem...
 
i am just guessing here, but is <HierarchicalDataTemplate.ItemTemplate> what you are missing?
 
But where is the toplevel menuitem being created by Contextmenu automagically?
@Julien I was just looking at that!
 
i am guessing your top level menu is being rendered by .ToString() of the type
 
6:15 PM
I just added:
    <HierarchicalDataTemplate.ItemTemplate>
        <DataTemplate>
            <MenuItem Header="{Binding Description}"
            ToolTip="{Binding Value}"
            Command="{Binding DataContext.AddToolbarControlCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
            CommandParameter="{Binding Value}" />
        </DataTemplate>
    </HierarchicalDataTemplate.ItemTemplate>
I think that's what I was missing.
 
could be right
 
(it compiles.. must work ;) )
And it's bound!
Yay!
(thank you, both of you, for taking a look.)
 
6:31 PM
man support sucks
every damn time I take a call from a customer, their VPN is broken, or they changed passwords, or the IPs of the macines changed
its always freaking something
 
Thats IT for you
 
yeah, im lucky somewhat though... my primary job is developement
support is something that only happens when everyone else is busy... for the most part
 
6:47 PM
good thing its friday
 
yay friday!
 
Someone on my Facebook wall today said "thank god it's TGIF today."
 
like going to the ATM machine :P
 
yes. and putting in your personal PIN number
 
7:17 PM
Hey all, what's the best way to create animated sprites in WPF?
I can't seem to see if video with MediaElements, or sprite sheets, or GIFs are the best way
 
define "best"
and depending on the animation, consider just using RenderTransform
 
@BradleyDotNET Hmm.. by best I think I mean most simple. I have these simple little videos created by a designer and I'm trying to map them onto a screen based upon a player position.
 
@BradleyDotNET @Julien My excitement appears to have been short-lived.
 
@LynnCrumbling Sorry to hear that
@Nolski For that, go with a sprite sheet
I would usually say GIF, but good luck getting one to work well in WPF
 
@BradleyDotNET Yeah.. it wasn't overriding the menuitem definition from the subitems.
It seems like ALL menuitems in the HierarchicalDataTemplate use that.
 
7:33 PM
@BradleyDotNET Cool. I'll go with that method then. Are there normally a lot of open source packages for this sort of thing? Normally python I'd just pip install whatever and import something instead of handling that myself. Not sure if wpf/c# is similar.
 
The one GIF one I tried sucked
haven't tried any sprite sheet ones yet
I'd just google and see if any codeplex/nuget packages pop up
 
8:02 PM
Hey @BradleyDotNET how are you doing today?
I had a question about Buttons and one about Commands sent to a UserControl
I think the Buttons one will end up being an easier one, that you might know off the top of your head
 
@KyleHumfeld Doing alright. Wishing I was in WPF at the moment instead of JS :(
But feel free to ask!
 
Namely, do Buttons have a minimum width? The reason I ask is that I've got this Grid layout and I've got Buttons in most of the 'cells', but they all spill out of their cells
I hear you, JS can be a real pain in the backside
So I've got this:
<Button Grid.Row="3" Grid.Column="1" Content="A" Grid.ColumnSpan="2" Width="10" Background="Blue" />
<Button Grid.Row="3" Grid.Column="2" Content="B" Grid.ColumnSpan="2" Width="30" Background="#33FF0000" />
And they look like this:
 
You can set a minimum width
but the panel doesn't have to listen to you
 
Maybe that's set by default?
I set a Width, but it's clearly ignoring that attribute
 
Oh, missed that :)
Any styles that might be changing the width?
 
8:06 PM
But if there's a behind-the-scenes MinWidth then maybe that's overriding?
 
In theory, your set should override
You could try setting the "MinWidth" property
 
I don't believe I have any global styling set up on Button elements
(without a Style)
 
I honestly don't know if there is a default minimum
 
Will try that
Wouldn't make sense - what if you wanted to have narrow but tall buttons, why would that not be feasible
 
Yeah, seems unlikely to me as well
 
8:07 PM
Yeah, MinWidth totally did it
 
though your use case also seems a bit unlikely
 
Strange that my explicit Width setting didn't override that
Designers are creative folks =)
 
its possible to set a button to be wider then its parent cell
 
you should try coding a UI in swing for Java
 
More creative than I am
 
8:08 PM
if there ever was a UI framework that ignored everything you told it... its swing
 
you are setting the width of the button
 
Thanks, @MarkW, I'll pass now that you've warned me =)
 
how wide is the column
 
MaxWidth of the column is 150
But it flexes based on the display
These are probably like 100 or 120 if I had to guess
 
maybe set minwidth of the column to the width of the button
 
8:09 PM
But setting MinWidth on the Buttons override what's apparently a global default and let them shrink down the way I want them to. So all good on that point. Should've tried that dur
Next question regards sending Commands to UserControls (using DepProps, not a VM per se at this point)
Namely, when I had Buttons, I set the Command of the Button to be something from my Binding so it fetched the Command from my MainPageVM and all worked as intended
Now I've swapped out those Buttons for UserControls with a ICommand DepProp, and I set:
if (this.Command != null)
{
this.Button.Command = this.Command;
}
 
i dont think you need a DP
 
in the OnLoaded method (which is being called, as the other DepProps are being handled properly)
 
your user controls can still bind against mainwindowvm directly
oh nvmd isee
 
Yeah, I'm sending in the Command in the UC inclusion, like this:
<local:CalculatorButton
Grid.Row="9"
Grid.Column="2"
Command="{Binding Button1_EToTheX_ClickCommand}"
WhiteString="1"
OrangeString="e^x"
BlueString="REGR"
/>
My four DPs are Command, WhiteString, OrangeString, and BlueString
The latter 3 are being set correctly
 
its because your xaml is initted in InitializeComponent
before your commands have initialized
 
8:14 PM
Should I be setting this.Button.Click = this.Command in my UC? At that point, am I dealing with a function rather than an iCommand
Interesting, tell me more
 
just to confirm
COmmand is null inside your UC's?
 
I haven't verified that yet, but I'll do so now. brb
 
you should be able to bind the button inside your UC to the DP property
directly in xaml
IF your command is coming through properly
 
so its definitely a threading issue
btw
tracked it down to a NotSupportedException when I call Add on the OC
 
@MarkW try wrapping your collection.add call in App.Current.Dispatcher.Invoke(() => { });
 
8:16 PM
from the thread that raised the event
 
Yeah, interesting, the string literals I'm sending in are (obviously) already created, but the Commands are null
 
I did :/

Dispatcher.CurrentDispatcher.Invoke(() =>
{
if (!_PickModules.Contains(dev))
{
_PickModules.Add(dev);
Console.WriteLine("Adding new device with ID of " + dev.DeviceID);
}
PropertyChanged(this, new PropertyChangedEventArgs("PickModules"));
});
unless that's wrong
 
yeah your approach wont work kyle. i was trying to do that yesterday
your UC is initted and DP's set in InitializeComponent
so you can't really DP against anything created in the class
 
Can I (in my Main's OnLoaded) connect up the Commands at that point?
 
your code verbatim worked Julien
thank you
 
8:17 PM
np
 
hurray!
 
yeah, there definitely seems to be a race condition here
 
items in my list :D
 
if you use a VM you solve this easy
you can create your VM's after initialize component and assign context to your buttons
 
Can I make the VM for each UC the same as MainPageVM?
 
8:20 PM
lol sure if you dont mind a bit of code smell
 
If you are going to do that, just bind to DPs instead
 
@BradleyDotNET what do you mean
 
Okay, let me stick with the DPs and no 'extra' VMs for this go-around (want to learn multiple ways)
So if I want to do that, how do I make my Commands work, as they're all null when the UCs are being created (in Init method on MainPage)
 
you cant, as far as i know
you could manually assign commands directly to your controls in c'tor
button1.ClickCommand = CmdClickCommand
 
Would there be a conceptual weakness to making a different VM for each of my buttons? Code proliferation, sure, but there's actually a potential good reason to do that with regards to their eventual contents (not TextBlocks, but drawn Glyphs)
 
8:23 PM
a vm for each button is the correct approach imo
 
Commands from the client side shoudl be bound
 
it only increases the flexibility you have
 
@Julien As usual, we'll disagree on that
 
:)
he is setting 4 custom properties on a UC
those may as well be VM properties
 
Aha, so I'd do that button1.ClickCommand = Button1ClickCommand in the OnLoaded in my MainPage.xaml.cs right?
 
8:23 PM
yup
 
What?
 
And that's the non-extra-VM way of doing it
 
No
Just bind the command directly
its a DP, right?
 
show us how
 
Yes
But when the UCs are being drawn, that's in MainPage's Init
 
8:24 PM
you cant bind against stuff that is initted in the class
 
And the Commands are all null at that point
 
Just do <myControl ClickCommand="{Binding Button1ClickCommand}"/>
 
button1clickcommand is null when the UC is created
 
Why
just instantiate it in the constructor
 
because the UC is created as part of init component
try it
 
8:25 PM
Right, which is why you intialize commands in the constructor
or do your lazy init way
either way, it will work
 
Sorry, I don't think I follow. Init the commands in MainPage's constructor, right?
 
Yes...
 
But they're defined in the VM, not in MainPage
 
Oh sorry
in the MainPage VM constructor
 
And the VM doesn't seem to have its stuff init'd by then
Let me check where those are init'd
Yeah, they're new'd in the function public MainCalculatorViewModel() (the constructor of the MainPage's VM)
They're at the bottom of that method, and I could move them up but that really shouldn't affect things, right?
e.g. Button1_EToTheX_ClickCommand = new DelegateCommand(touchedButton1_EToTheX);
Should I 'new' my vm before the this.InitiComp() in MainPage's constructor?
Would that make sure that things are in place before they're needed?
 
8:29 PM
try it
 
no, InitializeComponent goes first
but assuming you assign DataContext to a constructed object, the bindings will evaluate correctly
 
Figured
 
and since you can't really assign to an unconstructed object, it should work
and I've done it a bunch of times
 
Here's pretty much the whole constructor... see any errors with it?
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

MainCalculatorViewModel vm = new MainCalculatorViewModel();
vm.GoToAnotherPage += new GoToAnotherPageEventHandler(GoToPageWithIdentifier);
this.DataContext = vm;
 
Ok, seems reasonable
And your VM constructor
 
8:31 PM
Figured. And it worked before I started with the UserControls
public MainCalculatorViewModel()
{
changeButtonColor("White");
this.displayHelper = new CalculatorDisplayHelper();

/* START SETTING UP COMMANDS */
Button1_EToTheX_ClickCommand = new DelegateCommand(touchedButton1_EToTheX);
 
so since your UC lives on MainPage, when its created, its command binding is going to evaluate to null
 
That's an excerpt, will edit to pare out some of the stuff I was trying to pare out
 
because your commands are created later on in the chain
 
@Julien But the bindings should evaluate when DataContextChanged is fired
@KyleHumfeld And your UC def?
 
that is what i expected to happen when i was playing with it
 
8:33 PM
In the mainPage.Xaml I mean
 
but it is not how it behaved, for me at least
 
public CalculatorButton()
{
this.InitializeComponent();
this.DataContext = this;
//this.WhiteString = "White Text";
//this.OrangeString = "Orange Text";
//this.BlueString = "set in constructor";
this.Loaded += OnLoaded;
}
The props are set in OnLoaded, because they were always null if I tried evaluating them in the constructor
Excerpt of that:
private void OnLoaded(object sender, RoutedEventArgs e)
{
if (this.OrangeString != null)
{

this.OrangeTextBlock.Text = this.OrangeString;
}
else
{
this.OrangeTextBlock.Text = "[null]";
}
 
Ok... is the binding evaluating correctly?
Thats why I asked for the XAML
 
Sorry, didn't catch that
<Button
x:Name="Button"
HorizontalAlignment="Stretch"
BorderBrush="{StaticResource ButtonBackgroundColor}"
BorderThickness="5"
Padding="0"
Margin="0,-10"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
>
<Grid Background="{StaticResource ButtonBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="20*" />
<RowDefinition Height="1*" />
<RowDefinition Height="58*" />
<RowDefinition Height="1*" />
<RowDefinition Height="20*" />
<RowDefinition Height="1" />
The only Binding that it's using from MainVM is the Command, and that seems to be null at the time the UC's Loaded method is run
 
No, the using XAML :)
 
8:38 PM
Aha, understand the question now
Well, I copy/pasted from the Buttons I swapped out, and it was working for those. So I assume that if the syntax is supposed to be the same, that part is the same as well
However, there may be a typing issue there or something, where one is an ICommand and the other is... something else
 
I guess the other question is, how do you know it is null?
 
Actually, now that I notice, I am getting some Output stuff that may be relevant. Sorry, when I run it swaps away from Output tab and sometimes I forget to look there
Step-through told me it's null
 
Error: BindingExpression path error: 'Button1_EToTheX_ClickCommand' property not found on '_10biiFinancialCalcCS.CalculatorButton'. BindingExpression: Path='Button1_EToTheX_ClickCommand' DataItem='_10biiFinancialCalcCS.CalculatorButton'; target element is '_10biiFinancialCalcCS.CalculatorButton' (Name='UserControlRoot'); target property is 'Command' (type 'ICommand')
 
There you go
 
8:40 PM
So that sounds like it's just not found at all
 
the problem is that you set the data context in the constructor
take that line out of the UC constructor
 
Okay will try that
 
One of many reasons NOT to use separate VMs for UCs, DPs become almost unusable
Incidentally, I actually ran into this myself:
1
Q: Why is the binding data context set to the control's data context?

BradleyDotNETI have a user control called "CardDisplay", with an exposed Dependency Property called "CardValue". The control itself is basically just a textblock (an image really, but it works with a textblock and is easier to show) bound to this property, like so: <UserControl> <Grid> <TextBlock Te...

 
Wow, that did work. Thanks!
I don't fully understand the nuances there as to why that was a/the problem.
 
Because the binding was evaluating against the controls current data context
 
8:43 PM
Yeah, sounds like you really want to either got DPs or VMs but not both. Which is why @Julien, who favors VMs, hasn't really used DPs to any significant extent
 
which is normally inherited from the parent control/views data context
except you overrode that in the constructor
I wish it wasn't that way, but it is
 
But I was only using ivars, right? Like I never had xyz="{Binding abc}" anywhere
 
Not sure what you mean by "IVar"
but you did try to bind the Command
 
So when I set this.xyz = abc, why would it have looked anywhere other than the ivars (instance variables) in the current .xaml.cs file
properties or dps in this case
For example, this.Button.Command = this.Command... why would this.Command be set to anything other than the Command attribute of the <local:CalculatorButton> instance?
 
It would... I think you misunderstand
 
8:46 PM
Or it was and that's where I was using the {Binding}, but the binding target was set in the code for the UC.xaml.cs and that was overriding the MainPage's VM?
 
Thats right
 
Aaah, so the UCs are less encapsulated than I was assuming they were
 
What I discovered (and the answer cleared up) in my posted link
@KyleHumfeld On the contrary, they are highly encapsulated
but without DataContext being assigned, it will be inherited from the parent control
which is super useful
in fact, you use it all the time without realizing it
 
I was assuming that encapsulation meant that when I put them there, they wouldn't override anything in the calling context. But it feels to me like that's what they're doing
But no worries, that's just quibbling. Now that I get it (and hopefully won't forget it!), I shouldn't make that mistake again.
 
Yeah, it got me as well :(
I think it does what you would expect in WPF, but haven't tried it recently
 
8:50 PM
Okay, cool. Thanks for helping me to understand! I'll read through your post in more detail in a bit
afk a few
 
Is there a nice way to fish out the topmost adornerlayer? I only have a ref to the window.
 
Not a clue
 
Guess I could do template_PART but feels so ugly
 
Sometimes I feel like you work in a totally different framework :)
 
I do dumb things :)
 
8:58 PM
It's actually really a good learning experience for n00bs like me to hear you folks with tons of experience discussing different approaches. Most of it goes over my head, but I feel like hearing different reasonable viewpoints does aid with general understanding. =)
 

« first day (917 days earlier)      last day (3232 days later) »