« first day  last day (14 days later) » 

12:04 AM
Only one place should create the ApplicationVM. I recommend that you actually create it during the construction of the App.Xaml.cs page and place it in a static on that class. Then when you create the other VMs, reference that static and save it to the target properties on the VM. What you have now is two separate copies of ApplicationVM.
 
So
Don't make it an actual vie wmodel?
 
Only make one ApplicationVM and share it with the two other page VMs.
How it gets made, it doesn't matter, just make sure there is only one copy.
 
So what I did currently
is add the ApplicationVM to my ViewModel folder
and added it's instantiation to the ViewModelLocator
and it's weird... if I change the variable in my code then the designer updates.. it's like the proeprty isnt getting changed
but I placed messageboxes in the variables set methods and the value is definitely being changed.
When you say make only ONE ApplicationVM.. you meen only create the object once, correct?
 
right
 
So all of my current viewmodels will still extend ViewModelBase
including applicationVM ?
or will ApplicationVM extend ViewModelBase and all of my current VMs will extend ApplicationVM.. ?
I ask because we are trying to create a global variable VM for the entire application
To store user meta data, etc..
 
12:11 AM
Sure, it can't hurt. MVVM light is simply a wrapper to help with common operations. As long as ApplicationVM adheres to INotifyPropertyChanged (which is probably on the ViewModelBase) that is all you need to be concerned about.
 
Mind if I share my code with you?
 
I have to step away for a bit, dinner. :-)
Sure share the code. Back in about 15.
 
public class ApplicationVM : ViewModelBase, INotifyPropertyChanged
{
private bool _IsFilterToolBarVisible;
private bool _IsFilterManagementPanelVisible;

public event PropertyChangedEventHandler PropertyChanged;

public bool IsFilterToolBarVisible
{
get { return _IsFilterToolBarVisible; }
set
{ _IsFilterToolBarVisible = value; OnPropertyChanged("IsFilterToolBarVisible"); }
}
public bool IsFilterManagementPanelVisible
{
get { return _IsFilterManagementPanelVisible; }
set { _IsFilterManagementPanelVisible = value; OnPropertyChanged("IsFilterManagementPanelVisible"); }
There's what I have for ApplicationVM currently
public class MainWindowVM : ViewModelBase, INotifyPropertyChanged
{
public ApplicationVM AV { get; set; }
public string Title { get { return "TMS"; } }

public MainWindowVM()
{
AV = new ApplicationVM() { IsFilterToolBarVisible = false };
}
}
Main Window
MainWindowVM**
public class WorkPanelVM : ViewModelBase, INotifyPropertyChanged
{
public ApplicationVM AV { get; set; }


public IntermodalWorkPanelVM()
{
AV = new ApplicationVM() { IsFilterToolBarVisible = false };

}
Work panel VM that contains dock panel for filter bar
MainWindow.xaml toggle button to show/hide dock panel that is in Work panel VM:
<RibbonToggleButton x:Name="toggleFilters" Label="FILTERS" IsChecked="{Binding IsFilterToolBarVisible, Mode=OneWayToSource}"
IntermodalWork.xaml where dock panel that should be getting shown/hidden is:
<DockPanel Grid.Row="0" Style="{StaticResource FilterManagementToolBar}" Height="26" Visibility="{Binding IsFilterToolBarVisible, Converter={StaticResource BoolToVisConverter}}">
 
Why is IntermodalWorkPanelVM and MainWindowVM creating their own ApplicationVMs?
Create one in one place and share it to the other VM.
 
How do you share it to the other VM ?
 
12:26 AM
public IntermodalWorkPanelVM(ApplicationVM original) { }
Or where its created put it on a static member, say on the app class.

public static ApplicationVM AVM { get; set; }
 
add that to the main class/VM ?
 
I had a Silverlight project which would asynchronously get data and place it on statics. Then when the pages needed the data, they simply got it off of them. Pre loading before the page load.
 
or to the MainWindow?
 
Whatever works.
:-)
 
hmm
damn.. no dice
this line: public IntermodalWorkPanelVM(ApplicationVM original) { }
 
12:33 AM
The constructor, pass it on via its constructor.
 
pass the current declared one from MainWindow?
 
Yes
 
Nothing needs to be added to the Locator, correct?
Actually.. I just realized something
this project.. has a Data Access Layer (entities)
 
I am not familiar with the locator; but I don't believe so.
 
a Business access layer which constructs data from the DAL
currently we are registering the BAL objects, which are interfaces
in the locator
and passing them in
 
12:35 AM
That would work.
 
like so:
public IntermodalWorkPanelVM(IIntermodalWorkService intermodalWorkService)
{
this._intermodalWorkService = intermodalWorkService;

this.Items = this.IntermodalWorkService.GetIntermodalWork();





}
and the user control for the WorkPanel gets bound to Items
oh JK, not Items, but the instation from the IOC in the locator name 'InermodalWork'
 
Right IOC container to hold the appVM, then get it the same way from each VM.
Works as well.
 
hmm
 
I believe in the "Means justifies the ends" type of programming as long as its documented. :-)
 
Right, but our BAL
needs to be reusable
so storing WPF application specific variables in it is a bad idea
it needs to be as generic as possible
our BAL is going to be re-used in a Web App and tablet app
I'm just fairly new to this MVVM stuff so I wanted to do it properly
so im adding:
public ApplicationVM AVM { get; set; }
declaration in the IntermodalWorkPanelVM
constructor: public IntermodalWorkPanelVM(IIntermodalWorkService intermodalWorkService, ApplicationVM original)
{
this._intermodalWorkService = intermodalWorkService;
this.AVM = original;
 
12:40 AM
Looks good
 
yeah.. not working =/
Okay so... the Application VM code i sent you looks proper, right?
 
Why not? original is not null right?
 
with the get/sets ?
well.. its like the properties arent getting changes
changed*
 
Note that whatever is binding to the visible property needs a conversion between bool to a visible/not visable property.
 
Visibility="{Binding AVM.IsFilterToolBarVisible, Converter={StaticResource BoolToVisConverter}}"
thats on the dock panel in the intermodalwork.xaml
 
12:43 AM
kewl
 
somethings.. off
 
Are other items on the VMs displaying properly?
 
yeah
this is in my constructor for MainWindowVM
public MainWindowVM()
{
AV = new ApplicationVM() { IsFilterToolBarVisible = true };
}
that SHOULD make it appear
and it isnt, even in the designer
 
The designer won't necessarily reflect what is going on, on the class.
 
Right, so I ran it
and nothing
the MainWindow TOGGLE BUTTON that is supposed to hide/show it
IsChecked="{Binding AV.IsFilterToolBarVisible, Mode=OneWayToSource}"
has that
 
12:46 AM
Take out "oneWayToSource"
 
remove Mode completely?
 
Make it TwoWay
 
That says what is changed on the control gets expressed back to the bound property.
 
still nothing
 
12:47 AM
I can zip up my project I have and let you look at it. Would that help?
 
ummm
which project?
the one from your blog?
 
The one I created for your example.
it works/binds
 
I'm fairly certain when I added the ApplicationVM original to the constructor it did not make it in there
im flipping the true/false and i can see the button toggling in the designer
and my messagebox is saying its flipping between true/false
but its not reaching in to the IntermodalWorkPanel view
 
How is the IntermodalWorkPanelVM getting the VM?
 
public ApplicationVM AVM { get; set; } declared in the class
class declaration: public class IntermodalWorkPanelVM : ViewModelBase, INotifyPropertyChanged
{
public IntermodalWorkPanelVM(IIntermodalWorkService intermodalWorkService, ApplicationVM original)
{
this._intermodalWorkService = intermodalWorkService;
this.AVM = original;
 
12:50 AM
right, but where is the instantiation line?
How is the MainVMs copy getting to it?
 
uh
lol no idea
im having a brain fart here
 
var IWPVM = new IntermodalWorkPanelVM( MainWindowVM.AV, null);
That is the problem
You need to pass in the MainWindowVM.AV to the constructor.
 
I didnt even pass it to the contructor
i just put this inside it: this.AVM = MainWindowVM.AV;
annnd... it worked
 
So if you loaded it via the property why did you add it to the constructor?
 
i just took it out of the constructor
 
12:55 AM
k
 
and just set the property
to MainWindowVM.AV
That feels a little...shisty
 
Why dependency injection uses properties all the time.
Why, dependency....
 
why cant i just do this then...
Visibility="{Binding MainWindow.VM.IsFilterToolBarVisible, Converter={StaticResource BoolToVisConverter}}">
MainWindowVM.AV.IsFilterToolBarVisible ***
 
Because it looks on controls data context for a property named MainWindow.VM.... If it can't find it, it works up to the pages data contect and looks again for a named property MainWindow.Vm...
<on the control's data>
In my example on my site, I set the page's datacontext to the VM. Each child control can see the VM thanks to the page's data context. That is what makes it easier...
Binding works from the control, to its parent, to its parent....to the page's data context.
 
Which is strange
because
my MainWindow code behind in the view section
looks like this
public MainWindow()
{
var MainWindowModel = this.DataContext as MainWindowVM;
InitializeComponent();
}
the panel is included like this: <view:IntermodalWork DockPanel.Dock="Top"></view:IntermodalWork>
so why cant anything inside that view see that data context?
 
1:01 AM
THen someone is initializing a VM in the pages resource section.
and assigning it to the page's datacontext.
 
Ah... the culprit :
public IntermodalWork()
{
InitializeComponent();
var IntermodalWorkModel = this.DataContext as IntermodalWorkPanelVM;
IntermodalWorkModel.ShowDetailsCommandAction = ShowDetails;
}
that datacontext declaration is whats screwing up the inheritance isnt it
 
yes
Find in xaml where its being created and remove it. Then create it in the constructor and assign it like I have in my blog.

this.DataContext = new InerModalWorkPanelVM();
 
is that the proper way to do it?
and our way is wrong?
 
There is no 'right' or 'wrong' way of doing it. Just options.
 
ah
you mind if i ask you another question RQ? :D
nothing as crazy as this
 
1:05 AM
sure
 
just curious how you bind property changes to a regular button
so now that my tolbar shows
it has a 'Manage' button
which will show a dock panel which is located in the MainWindow
 
You mean the text of the button?
 
and then that panel will have a button to close the panel
yeah sorry
<Button Content="Test" Width="200" x:Name="ToggleFilterManagementPanel"></Button>
the filter toggle button from earlier shows the toolbar, sort of like a favorites list
that you ahve in your browser
 
Content="{Binding MyPropertyOnTHeVMWhichHasAButtonName }"
 
this button will open a panel that is in MainWindow
which will allow you to edit the filters
 
1:07 AM
override the OnClick event and close the panel in code behind
 
Okay so you cant do it with bindings?
 
You can, but I can't explain it in chat.
Get it working in code behind first.
Then try to find a way in Xaml.
 
okay :)
 
Remember, Xaml is simply code behind expressed it markup.
 
I appreciate all of your help
 
1:08 AM
Nothing more, nothing less.
 
You've been a tremendous help for me... our project lead left our business so this got dumped in.. less experienced.. peoples laps haha
 
MVVM is only three tiered data logic separation with a fancy name.
IMHO
:-)
 
BTW
is there anything I can do on Stack Overflow to help your rep or give you points or w/e
 
You already did. I am a Microsoft MVP in C#, recognized for my work in the 'community' which, this is. :) I appreciate the offer.

If you want to do something, try to answer questions on StackOverflow. It will help the community, but actually help you even more.
That is how I became an MVP, started because I needed help with an Excel VSTO smart document back in 2006.
ttyl
 
Awesome
thanks for the help, again.
 

« first day  last day (14 days later) »