How to bind IsSelected Property of ListBoxItem with Mode Two way using WinRT Xaml Toolkit in Windows 8.1 - mvvm

I have a Windows 8.1 Application
I am using WinRT Xaml Toolkit to bind my IsSelected Property to my ViewModel as the Binding is supported out of the box.
I have included the following Namespace
xmlns:Extensions="using:WinRTXamlToolkit.Controls.Extensions"
Here is the ListBoxItem of my XAML
<ListBoxItem Extensions:ListBoxItemExtensions.IsSelected="{Binding MyBool, Mode=TwoWay}">
<TextBlock Text="MyText" />
</ListBoxItem>
However I am unable to bind it TwoWay, the binding is working only from ViewModel -> View.
Is this a limitation of the Extension. If yes how do I achieve two way binding?
I would be very glad if someone can point me in the right direction.
Thanks in Advance.

You cannot do this, unfortunately.
You can, however two-way bind to the ListView.SelectedItem.
If you need more than one selected item, the WinRT Toolkit has BindableSelection: http://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit/WinRTXamlToolkit.Shared/Controls/Extensions/ListViewExtensions.cs
Best of luck!

Related

Xamarin Forms XAML Design Instance

Is there a way to enable design context in Xamarin Forms XAML pages to enable intellisense? It works in WPF but for years I couldn't get it to work in Xamarin Forms.
So if you compile your xaml by setting the attribute in code somewhere, and then include the xaml snippet below, you can use design time data contexts and get the intellisense.
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MySpace
{
public partial class App {}
}
<Page
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=list:TestViewModel}"
xmlns:list="clr-namespace:PolyhydraGames.Test.ViewModels"
.../>
Normally you should get it by default. Otherwise try Ctrl + Space. You do not need any additional code. Note it will not show you the intenseness for binding objects but all the design time elements.

How to Dynamically load EXTERNAL MVVM and NON MVVM controls using Caliburn Micro

I am loading controls dynamically from the web server from separate XAP files. After creating an instance I want to show them in tab Pages. The controls can be MMVM controls using CM but also non MVVM standard controls.
Before trying the tab I tested to simply show a control dynamically on the page by using:
<ContentControl Name="TestControl" />
Test control is a property of Type UserControl which is set via creating a new Instance of a dynamically loaded control. Now this gives me an error that it can't find the view. In case of non MVVM controls there is of course no view, so how do I load a non MVVM control?
I tried to make the test control a MVVM control, but still get the cannot load view error. Makes sense as such instance is not created. If I create an instance of the dynamically loaded view besides the view model, how do I "Add" this so that CM finds it?
Last but not least, how do I bind this to a tab control in Silverlight? The idea is to have a collection of user controls (plugins) which each is rendered in its separate tab page.
Thanks for any help.
(I got this done in no time NOT using MVVM, still not sure if MVVM is worth all the complexity)
There's no such thing as "mvvm control". MVVM is just a pattern not a control type. Basically, in Caliburn you don't need to work vith UserControls or Views directly, but if you pick the ViewModel first approach, Caliburn framework should be able to find the matching view for you. In your case since you're loading XAP files dynamically, you need to add them to the list of assemblies Caliburn looks to find a View/ViewModel (and bind them together) and this is done through IAssemblySource interface. According to the documentation here:
So, what is AssemblySoure.Instance? This is the place that
Caliburn.Micro looks for Views. You can add assemblies to this at any
time during your application to make them available to the framework,
but there is also a special place to do it in the Bootstrapper.

Selected Items using MVVM in WinRT

I'm struggling to find a way to bind the SelectedItems property in a ListView to the view model.
Previously I used this: http://www.codeproject.com/Articles/412417/Managing-Multiple-selection-in-View-Model-NET-Metr which no longer works in the RTM release.
Any help is much appreciated!
Thanks in advance :)
You could look at the ListViewExtensions.BindableSelection from the WinRT XAML Toolkit on CodePlex.
Turns out binding to the attached property was failing because the type of the attached property was being seen as
From the output window in Visual Studio:
type ('null')
After further research it became apparent that any generic class would fail to bind with this exact error. As a quick fix I simply changed the type to "object".
You can direct bind the selected item to another ui element or a property in your mvvm class

MVVM Light: Adding EventToCommand in XAML without Blend, easier way or snippet?

Can anyone tell me what the actual syntax is for EventToCommand class. From what I believe is that EventToCommand class works with Silverlight / WPF and WP7, hence I think its a better choice to go down.
From what I believe, I can add any click event and get it forced into my ViewModel, but I am having an issue in finding the best way to do this.
I know you can add it without Blend, but are there snippets available?
Or is there an easier way to add it via VS 2010? Any help or if anyone knows of a good tutorial on this would be great.
Suppose you use .NetFramework4:
First add namespace:
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
Syntax for the Loaded event.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<cmd:EventToCommand Command="{Binding Mode=OneWay, Path=LoadedCommand}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
I updated my project and it looks like they moved the command to:
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
0) if you dont't know WPF and MVVM, then read Josh Smith article about WPF and MVVM pattern https://msdn.microsoft.com/en-us/magazine/dd419663.aspx
1) In your project add package (through NuGet) MvvmLightLibs
2) add reference to System.Windows.Interactivity
3) In "View" XAML add:
a)
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
b)
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<command:EventToCommand Command="{Binding OnClosingCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Window>
4) In ViewModel add necessary property
public ICommand OnClosingCommand
{
get
{
return new RelayCommand(() => SomeMethod());
}
}
P.S. In your View should be specified DataContext (XAML)
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
It is work. I myself just learned.

SharePoint Navigation Menu - Multi Level

I'm looking into integrating some Telerik Components into our MOSS Installation. I'd figure I would kill a few birds with one stone and work on the Navigation Menu first.
I'm slightly new to SharePoint, and pulling hair at some of it's oddities.
We have some requirements for our Navigation menu:
Security Trimmed
Multi-Level Navigation
As best as I can tell, there doesn't seem to be a way to get security trimming without using SharePoint's out of the box Navigation Settings. Am I wrong?
Is there a way to get these Navigation Settings to go more than two levels deep?
EDITS
I'm using the Global Navigation, located at / > Site Settings > Modify Navigation
Haven't used the Telerik control.
I suspect you should be able to accomplish this with basic properties, something like StaticDisplayLevels="2" with 2 being the number you want.
The security I believe would be handled on your datasource that the control uses.
Again, I haven't used the telerik control so I'm sure it's a bit different, looking at the product info for this control it appears to be a matter of figuring out what the properties are that you need to adjust. There must be some documentation that came with it?
Savageguy is correct that you modify this on the datasource, an example:
<PublishingNavigation:PortalSiteMapDataSource
ID="MainNavigationDataSource"
runat="server"
EnableViewState="true"
SiteMapProvider="GlobalNavSiteMapProvider"
StartingNodeOffset="0"
ShowStartingNode="false" />
and then you can use any sort of control (databound) to render your menu. I´m using a repeater for my menu:
<asp:Repeater runat="server" ID="MenuRepeater"
DataSourceID="MainNavigationDataSource">
you are not required to use any other components other than SharePoint Menu but you have to add a small piece of script in the body tag:
< body onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">