Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all 1760 articles
Browse latest View live

New Post: Hook into ContentControl view creation

$
0
0
The simplest way is to re-define the View generation callback: ViewLocator.GetOrCreateViewType:
var baseGetOrCreateViewType = ViewLocator.GetOrCreateViewType;
ViewLocator.GetOrCreateViewType = (type, displayLocation, context) =>
                                                       {
                                                            var view = baseGetOrCreateViewType(type, displayLocation, context);
                                                            //... add your custom code to the view...return view;
                                                       };
Such function is invoked every time a view is generated. On a side note: there is an high chance that you still need the custom code in CreateWindow, since a view that has to be displayed in a separate window, is forcefully wrapped inside a Window control, generated by the IWindowManager.

New Post: Bind a viewmodel and its view without displaying the view?

$
0
0
CM will try to bind a view-model/model together (hence to display the view) if you either specify the View.Model explicitly, or use naming convention:
publicclass MyViewModel
{
        publicobject MyVMProperty { ... }
}
<ContentControlx:Name="MyVMProperty"/><ContentControlcal:View.Model="{Binding Path=MyVMProperty}"/>
So, if you simply ignore the list property in the view, no control will be generated, since CM naming conventions rely on the fact that exist both a property on the view-model and a control in the view having the same name.

New Post: Master/Details with multiple views for Master and for Details

$
0
0
It depends. :)
If your master and detail view-models are the same, indipendently from the actual view (which is the case, I suppose), you can explicitly bind View.Model to the master vm, and use a binding over View.Context to switch between views. The same can be done with the details part.
If, on the contrary, different view-models are used, then the best approach would be using a conductor One-Active to manage both Master and Detail view-models.

Regarding how to bind currently selected item from the master, to display the details view, consider this scenario:
  1. Your shell view-model exposes a Master view model, which is a conductor one-active.
  2. Your shell view hosts both master and detail views: the master view is bound through View.Model (not by naming convention), and View.Context is bound to a view-model property (e.g. MasterMode) that lets you select which type of view should be displayed; the details view is bound through View.Model (databound to Master.SelectedItem), and its View.Context should be bound to another propery (e.g.DetailsMode) used to select the proper details view (I am assuming the single-view-model/multiple-views scenario).
  3. The Master view is only responsible for displaying its content (e.g. the list of files), and at most it can display a summary of the currently selected item (e.g. the information available on the status bar in explorer). Multiple views should be created, to match available MasterMode values.
  4. The details view could be different, depending on the actual selected item, and for each type of item, multiple views should be created, to match available DetailMode values.
In case different view-models should be used, the shell view-model should expose a MasterHost property (a conductor one-active) and (eventually) a DetailsHost, moreover some more logic should be provided to generate details view-models when needed (I have assumed the most complex scenario, where completely different Master view-models generate multiple different Detail view-models... this is hardly a common scenario...).

Created Unassigned: Buttons inside a Flyout [360]

$
0
0
Hi together,

i have a little problem using Buttons inside of a Flyout.
The Buttons methods should be invoked via caliburn.message.... .
Every time the application starts, the Buttons wont react.
Open the Flyout again, everthing works fine.

Has anybody an idea whats the reason for this?


New Post: IHandle not working on View's behind code

$
0
0
I currently have 3 separate projects in a solution, Main application which contains my bootstrapper, a View project, and a ViewModel project

The main application's bootstrapper is set up correctly to tie the view and viewmodel together.

I need to be able to access the View's behind code from the viewmodel, so i set the View's class declaration as such

public class MyView: Window, IHandle<string>
{
public void Handle(string data) { }
}

However, when i Publish from my viewmodel, this never gets hit. If i setup the IHandle implementation in the bootstrapper class instead, then it does fire off there, but that does me no good, as i need to be at the view instance level in order to do the things i want to do.

in my bootstrapper, i am subscribing to the IEventAggregator correctly since IHandle IS working from the bootstrapper.

any idea what i'm doing wrong or am i going about access the behind code in the wrong way?

New Post: IHandle not working on View's behind code

$
0
0
You need to have the ViewModel subscribe to the IEventAggregator.


New Post: IHandle not working on View's behind code

$
0
0
Let me elaborate on the problem.

UtilityViewModel.cs (from my ViewModel project)
public class UtilityViewModel {
private IEventAggregator myevent;
 [ImportingConstructor]
        public UtilityViewModel(IWindowManager window, IEventAggregator events)
        {
myevent = events;
myevent.subscribe(this);
...

         
        }
        public void SendDataBackToBehindCode(string message)
        {
            //this will get called
            myevent.Publish("hello");
         }
View.xaml.cs (From my View project

public partial class UtilityView : Window, IHandle<string>
{
  public void Handle(string data)
 {
  // it never gets here
  }
}
  
but again, if i put the public void Handle in my bootstrapper code, then THAT codes does get fired, so i know the "publish" is working.. just not from the View's behind code

New Post: IHandle not working on View's behind code

$
0
0
Hmm, looks correct. Have you place a breakpoint in the constructor to see you're getting the right values for window and events?



New Post: IHandle not working on View's behind code

$
0
0
And you should be using IoC.Get<IEventAggregator>() instead of passing those values. Thats why it's there.


New Post: IHandle not working on View's behind code

$
0
0
do i need to do any subscriing in the View's behind code or simply just that IHandle like i have it?

ive replaced those parametesr with just calling IoC.Get<IEventAggregator>(), but the Handle method is still not getting called.

i put a break point in my viewmodel to check to see if my event is returning null or not and its not null.

any ideas? is CM supposed to look at the View's behind code to begin with to see if its implementing IHandle?

New Post: IHandle not working on View's behind code

$
0
0
is it possible that the bootstrapper is "overriding" my View class for IHandle?

because like i said, if i implement IHandle<string> inside my bootstrapper class, it gets hit there.. theoretically if i have my bootstrapper AND my view both implement IHandle<string>, are they BOTH supposed to get called?

New Post: IHandle not working on View's behind code

$
0
0
I don't know what happens if you have behind code in the view. I typically delete it.


New Post: IHandle not working on View's behind code

$
0
0
ah okay i misunderstood. So you've never be able to use IHandle on a View's behind code before?

From my view model class, i am trying to raise an event so that my view's behind code can run some things related to storyboards which i have no access to in the viewmodel (and wouldn't want to since that would break MVVM).

for now, im just using an invisible textbox, ontargetupdate, binding my args to the textbox's Tag property, so that i can get to the View in order to access the storyboard object to do direct manipulation to it. I was hoping IHandle would work with behind code so that i wouldn't have to do this nasty work around..

guess IHandle allows me to pass parameters around to other viewmodels, but not to other view behind codes... how disappointing

New Post: IHandle not working on View's behind code

$
0
0
I think you've misunderstood me. I was only referring to your use of the Views, not the IEventAggregator. I've look at the code the IEventAggreator and it doesn't have anything specific to Views or ViewModels. I've actually copied the code out and used it in a WinForms app. The Subscribe function simply adds the object passed into a list. When a publish occurs, it iterates the entire list looking for objects that implement the IHandle interface that match the type being published. Very simple. Without a sample, it's hard to say why you aren't catching the expected publish.


New Post: IHandle not working on View's behind code

$
0
0
if thats all its doing then i have no idea why the view's behind code isnt being evaluated. do instances get removed automatically from the list? i will provide sample code in the next day or so when i have some time.

New Post: IHandle not working on View's behind code

$
0
0
ok got it working.

the problem was my bootstrapper had 2 instances of the IEventAggregator so i was pulling the wrong one when i was subscribing from the View's behind code.

thanks for your help though. cheers

New Post: ConventionManager configuration for code-behind dependency properties

$
0
0
Did you find a solution Rufus?

I have a similar issue,
I am adapting a project with views and viewmodels not written with Caliburn in mind, and it has dependency properties in the code behind. How do I get the automatic binding to work appropriately for code behind dependency properties?

Thanks,
Jeroen.

New Post: ConventionManager configuration for code-behind dependency properties

$
0
0
Hello Jeroen!

I'm very sorry, but I didn't find a solution - finally I changed the whole architecture.

Best regards

Rufus

New Post: Query String

$
0
0
I am using the MUI library https://mui.codeplex.com/ with Caliburn for a WPF project. so I switched my code to use view first using MEF bootstrapper and a contentloader class.

How do I pass items between views? I added a query string but I am not sure how to get it on the receiving viewmodel. I created a property with the same name as the query string parameter and I thougth that caliburn would automagically parse and set the property but it didn't.

Any idea?

New Post: Documentation for 2.0

$
0
0
Where is the documentation for 2.0?
Viewing all 1760 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>