Rated 5 Stars (out of 5) - I want Use it By .NET 4.0
↧
Reviewed: Caliburn.Micro v1.5.2 (一月 02, 2014)
↧
Closed Unassigned: [Phone] Dialogs [355]
A. I wish that the DialogHost would be public. That way, we would be able to style it a little, and control parameters such as the glass opacity and where the dialog is opened.
B. Given A, How would you implement a full screen dialog?
Thanks!
Comments: Not an issue but a question.
B. Given A, How would you implement a full screen dialog?
Thanks!
Comments: Not an issue but a question.
↧
↧
New Post: pass command from 3rd party control to view model
I've rewritten my app to use caliburn and mvvm its taken ages and has been difficult. my final hurdle is to wire the a 3rd party control to call my refresh method in the viewmodel
the 3rd party control has an event handler in the view, when this is triggered I just want to call myviewmodel.refresh - how is this best accomplished
the 3rd party control has an event handler in the view, when this is triggered I just want to call myviewmodel.refresh - how is this best accomplished
↧
New Comment on "Customizing The Bootstrapper"
I'm trying to follow the advice above under "Using Caliburn.Micro in Office and WinForms Applications".
In a Winform, I have this code:
myBootStrapper = new AppBootstrapper(false);
myBootStrapper.Start();
Where the bootstrapper is:
public class AppBootstrapper : BootstrapperBase
However, I can't pass the "false" in to the base constructor, or figure out how to indicate that useApplication is set to false.
What am I missing?
Thanks!
↧
New Comment on "Customizing The Bootstrapper"
Got it - I was missing:
public AppBootstrapper(bool useApplication) :base(useApplication)
↧
↧
New Post: pass command from 3rd party control to view model
You can treat the event as you would on the view in the view model...
Just wire up the event to the viewmodel through Message.Attach="[Event EventName] = [Action SomeAction($eventArgs)]" on the control in question. Assuming you know the signature of the Method which can be discovered through just creating the handler on the view first then recreating on the viewmodel by hand (copy/past) with said signature..
or use IEventAggregator on the view... and create an object that you want to send through to the viewmodel with contents of which say "refresh" or something... creating an object of IEventAggregator on the view is relatively easy it doesn't include Injection.
I am sure some would disagree on the later call..
in the end both methods are still in the realm of separation of concerns...
Just wire up the event to the viewmodel through Message.Attach="[Event EventName] = [Action SomeAction($eventArgs)]" on the control in question. Assuming you know the signature of the Method which can be discovered through just creating the handler on the view first then recreating on the viewmodel by hand (copy/past) with said signature..
// For Examplepublicvoid SomeAction(EventArgs e){ if (e.SomeProperty == somethingtrue) Refresh(); } || publicvoid SomeAction(){ Refresh(); }
I am sure some would disagree on the later call..
in the end both methods are still in the realm of separation of concerns...
↧
New Post: pass command from 3rd party control to view model
thanks that's really great, I've managed to message.attach to refresh my data when the pulltorefresh action on the listbox is called.
finally I would like to call this after the refresh - which stops the animation on the telerik control....
(code behind)
this.radDataBoundListBox.StopPullToRefreshLoading(true);
how would I do this from the viewmodel
sorry for the very basic questions
finally I would like to call this after the refresh - which stops the animation on the telerik control....
(code behind)
this.radDataBoundListBox.StopPullToRefreshLoading(true);
how would I do this from the viewmodel
sorry for the very basic questions
↧
New Post: pass command from 3rd party control to view model
I too am a Telerik user and haven't gotten to the point to using pulltorefresh and therefore never looked how to wire up the completion, I suspect that the completion event comes only on the view side so you would probably have to handle on the view which is entirely ok. Ieventaggregator would be my first go to on this.. as I stated before snag instance of it and then listen for "somecompletioneventyoucreate" is published. I have some snippets laying around if need be for the instance of IeventAggregator in a view, it does smell but it works...
Another possibility is to pull an "instance" of the control into the viewmodel via the OnViewLoaded(object view) override and then using GetView() to get access to typed information then cast control to RadDataboundListBox since that is what it is then when you are doing do "controlname.StopPulToRefreshLoading(true);" call to stop animation.
Some are purists some are not, if it's entirely view related then do it on the view... but if it entails something else in the viewmodel then it gets slightly more complicated, just have to see about marshalling around the events you want to occur.
due to the nature of the beast that is WP and trying to force a paradigm that can be anti-pattern in some cases, this would be one of them.. Testability can be troublesome in this case due to the code involved, especially if the control name ever changed.
there aren't ever very basic questions when it comes to this stuff :)
Another possibility is to pull an "instance" of the control into the viewmodel via the OnViewLoaded(object view) override and then using GetView() to get access to typed information then cast control to RadDataboundListBox since that is what it is then when you are doing do "controlname.StopPulToRefreshLoading(true);" call to stop animation.
Some are purists some are not, if it's entirely view related then do it on the view... but if it entails something else in the viewmodel then it gets slightly more complicated, just have to see about marshalling around the events you want to occur.
due to the nature of the beast that is WP and trying to force a paradigm that can be anti-pattern in some cases, this would be one of them.. Testability can be troublesome in this case due to the code involved, especially if the control name ever changed.
there aren't ever very basic questions when it comes to this stuff :)
↧
New Post: pass command from 3rd party control to view model
I'm not a purist - just interested in learning something new. I've just created a new instance and used GetView() to stop the animation. Works well and I don't need to introduce EventAggregators (if I do this I will spend the next 2 weeks thinking about these)....Looks like I could be finally ready to publish v.2 of my app - a couple of weeks late but it looks good and should be much easier to maintain than all my previous code.... many thanks!
↧
↧
New Post: Handling Focus with Caliburn.Micro
I have been searching for a solution for setting Focus from ViewModel. I couldn't find one as I was expecting, so I wrote a one for myself. I am posting here, so that I can help someone.
The following class will Set Focus to a named control in View, or if there is no named control then look for a control where the binding is defined with the property from ViewModel. For the later part, it consumes the binding conventions defined in Caliburn.Micro.ConventionManager.
This solution will work only for ViewModel that are derived from Caliburn.Micro.Screen or Caliburn.Micro.ViewAware.
I thought of using this as a service so I defined the class as static.
The following class will Set Focus to a named control in View, or if there is no named control then look for a control where the binding is defined with the property from ViewModel. For the later part, it consumes the binding conventions defined in Caliburn.Micro.ConventionManager.
This solution will work only for ViewModel that are derived from Caliburn.Micro.Screen or Caliburn.Micro.ViewAware.
I thought of using this as a service so I defined the class as static.
public static class FocusManager
{
/// <summary>
/// Set Keyboard Focus to the element named after the property.
/// </summary>
/// <param name="screen">View in which the control exists.</param>
/// <param name="propertyExpression">Expression for the property <example>()=>Property</example></param>
/// <returns>true, if focused is set.</returns>
public static bool SetFocus(this IViewAware screen ,Expression<Func<object>> propertyExpression)
{
return SetFocus(screen ,propertyExpression.GetMemberInfo().Name);
}
/// <summary>
/// Set Keyboard Focus to the element named after the property.
/// </summary>
/// <param name="screen">View in which the control exists.</param>
/// <param name="property">Name of the property</param>
/// <returns>true, if focused is set.</returns>
public static bool SetFocus(this IViewAware screen ,string property)
{
Contract.Requires(property != null ,"Property cannot be null.");
var view = screen.GetView() as UserControl;
if ( view != null )
{
var control = FindChild(view ,property);
bool focus = control != null && control.Focus();
return focus;
}
return false;
}
/// <summary>
/// Find the control in the Visual Tree and also looking at the Binding Expression.
/// </summary>
/// <param name="parent">View in which the control exists.</param>
/// <param name="childName">Named of the property which is defined the ViewModel.</param>
/// <returns></returns>
private static FrameworkElement FindChild(UIElement parent ,string childName)
{
// Confirm parent and childName are valid.
if ( parent == null || string.IsNullOrWhiteSpace(childName) ) return null;
FrameworkElement foundChild = null;
int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for ( int i = 0; i < childrenCount; i++ )
{
FrameworkElement child = VisualTreeHelper.GetChild(parent ,i) as FrameworkElement;
if ( child != null )
{
BindingExpression bindingExpression = GetBindingExpression(child);
if ( child.Name == childName )
{
foundChild = child;
break;
}
if ( bindingExpression != null )
{
if ( bindingExpression.ResolvedSourcePropertyName == childName )
{
foundChild = child;
break;
}
}
foundChild = FindChild(child ,childName);
if ( foundChild != null )
{
if ( foundChild.Name == childName )
break;
BindingExpression foundChildBindingExpression = GetBindingExpression(foundChild);
if ( foundChildBindingExpression != null &&
foundChildBindingExpression.ResolvedSourcePropertyName == childName )
break;
}
}
}
return foundChild;
}
/// <summary>
/// Get the BindingExpression for the control using <see cref="Caliburn.Micro.ConventionManager"/>
/// </summary>
/// <param name="control">Control for which,BindingExpression is required.</param>
/// <returns>BindingExpression for the control.</returns>
private static BindingExpression GetBindingExpression(FrameworkElement control)
{
if ( control == null ) return null;
BindingExpression bindingExpression = null;
var convention = ConventionManager.GetElementConvention(control.GetType());
if ( convention != null )
{
var bindablePro = convention.GetBindableProperty(control);
if ( bindablePro != null )
{
bindingExpression = control.GetBindingExpression(bindablePro);
}
}
return bindingExpression;
}
}
↧
New Post: Stealing focus
If you are looking for a service for setting Focus, I have a solution in Handling Focus with Caliburn Micro
↧
New Post: [WP8] Implementing simple loading overlay
In my Windows Phone 8 application im executing long running task and want to display loading overlay for user while task is executing.
My current solution is something like this:
All suggestions welcome, as im still starting to learn this awesome framework :)
My current solution is something like this:
public async void DoWork()
{
var overlay = new MessageOverlayViewModel();
overlay.Message = "Getting your location";
this.windowManager.ShowPopup(overlay);
// Get locations async
overlay.Message = "Loading data";
// Load data async
overlay.TryClose();
}
This works "ok", but there are still many question marks: AppBar is still visible when overlay is "active", maybe because AppBar is set in conductor page and DoWork() is inside one pivot item VM? Another question mark is how to handle back button, now if user hits back, whole app is closed.All suggestions welcome, as im still starting to learn this awesome framework :)
↧
New Post: Message.Attach on a custom event
Hi,
Did you make any progress on this?
I have almost the identical problem.
Did you make any progress on this?
I have almost the identical problem.
↧
↧
New Post: Define a convention to add custom converter based on control type and tag property value
I want to custumize my caliburn conventions to handles a custom control that here we can call BaseText.
If one of controls in use that derive from BaseEdit has the Tag property in xaml set equals to custom converter name, I want to attach this converter to binding.
I have tried as show above:
I can achieve my goal with a custom attribute on view-model, but I prefer to do this via ConventionManager.AddElementConvention. It's possible?
Thanks in advance.
If one of controls in use that derive from BaseEdit has the Tag property in xaml set equals to custom converter name, I want to attach this converter to binding.
I have tried as show above:
ConventionManager.AddElementConvention<BaseText>(BaseText.EditValueProperty, "Text", "EditValueChanged")
.ApplyBinding = (viewModelType, path, property, element, convention) =>
{
var bindableProperty = convention.GetBindableProperty(element);
if (!ConventionManager.SetBindingWithoutBindingOrValueOverwrite(viewModelType, path, property, element, convention, bindableProperty))
return false;
if ((string)element.Tag == "DateTimeToTimeSpanConverter")
{
Binding binding = BindingOperations
.GetBindingExpression(element as DependencyObject, bindableProperty)
.ParentBinding;
binding.Converter = customConv;
}
return true;
};
but statement binding.Converter = customConv
raise an error. Where is my mistake?I can achieve my goal with a custom attribute on view-model, but I prefer to do this via ConventionManager.AddElementConvention. It's possible?
Thanks in advance.
↧
New Comment on "Introduction"
Typo: "The “bubbling” nature of Acton Messages" --> should be "The “bubbling” nature of Action Messages"
↧
New Comment on "Basic Configuration, Actions and Conventions"
Cool. Thank you.
↧
New Post: ListBox SelectionMode="Multiple" and SelectedItems conevention
I have a user control that contains a ListBox with the SelectionMode set to Multiple. I use the same View and ViewModel source files in an Excel solution (with a WPF document pane) and a standalone WPF application.
In the Excel version it works as expected, but in the standalone WPF the selected items are not being reflected in the UI despite the code having a CollectionChanged handler registered.
The logger shows me that when used within Excel, a message appears for the ListBox that says 'SelectedItems convention applied to ..' and selecting items does not generate further messages but fires the CollectionChanged event.
In the standalone WPF solution I do not see the 'SelectedItems convention applied to ...' message for the ListBox element. Selecting items results in a 'SelectedItemChanged' message appearing in the log instead of firing the CollectionChanged event.
Both apps are using Caliburn.Micro 1.5.2.
Does anybody know what might be causing this discrepancy.
Regards
Alan
In the Excel version it works as expected, but in the standalone WPF the selected items are not being reflected in the UI despite the code having a CollectionChanged handler registered.
The logger shows me that when used within Excel, a message appears for the ListBox that says 'SelectedItems convention applied to ..' and selecting items does not generate further messages but fires the CollectionChanged event.
In the standalone WPF solution I do not see the 'SelectedItems convention applied to ...' message for the ListBox element. Selecting items results in a 'SelectedItemChanged' message appearing in the log instead of firing the CollectionChanged event.
Both apps are using Caliburn.Micro 1.5.2.
Does anybody know what might be causing this discrepancy.
Regards
Alan
↧
↧
New Post: ListBox SelectionMode="Multiple" and SelectedItems conevention
After several hours of searching I noticed that I was missing the Conventions.Apply() line from my bootstrapper.
↧
New Post: [WP8] Implementing simple loading overlay
Anyone? :)
All suggestions and ideas welcome.
All suggestions and ideas welcome.
↧
New Post: WPF button Command vs Content
I have a bug related with the use of commands in buttons in WPF.
I have the following code
Yet, when i withdraw the 'x:Name"CancelCommand"' having
Can someone help me clarify if there is some kind of problem regarding the use of Caliburn naming conventions and the use of Commands?
Thx,
lcrsantos
I have the following code
<Button x:Name="CancelCommand"
Content="Cancel"
Command="CancelCommand" ... />
When I render this button the text appearing in the button is something like Framework.UI.RellayCommand (the namespace of the command) instead of the content I define.Yet, when i withdraw the 'x:Name"CancelCommand"' having
<Button Content="Cancel"
Command="CancelCommand" ... />
I have the desired behaviour and text within the button.Can someone help me clarify if there is some kind of problem regarding the use of Caliburn naming conventions and the use of Commands?
Thx,
lcrsantos
↧