in my Windows Phone application I have following scenario:
I have two ListBox'es f.e lbx1 and lbx2
ViewModel loads data to lbx1
User tap on ListBox, command is fired, ViewModel set visibility of lbx1 to collapsed and lbx2 to visilbe.
Now I want to do following thing: when lbx2 is visible I want to intercept OnBackKeyPress event in My ViewModel so that I can change visibility of lbx1 to visible and lbx2 to collapsed.
Is it even possible with mvvm.light ?
Ok, found my aswer:
In page.xaml insert:
<i:Interaction.Triggers>
<i:EventTrigger
EventName="BackKeyPress">
<GalaSoft_MvvmLight_Command:EventToCommand
Command="{Binding BackKeyPressCommand}"
PassEventArgsToCommand="True"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
Where Command is my ViewModel command, and PassEventArgsToCommand="True" enables me to cancel event when event is fired
Related
I have an UWP application with ReactiveUI. I have the following in my DataTemplate:
<MenuFlyoutItem Icon="Edit"
Text="{Binding Resources[EditLabel]}">
Since it is a template, I can't access them in my code behind. So how can I setup the binding here?
I tried the Command but then I can only bind to the item itself and not to the ViewModel of the containing view.
EDIT: I adjusted it that way:
<MenuFlyoutItem Icon="Edit"
Text="{Binding Resources[EditLabel]}"
Command="{Binding DataContext.EditAccountCommand, ElementName=AccountList}"
The Binding does work. I wanted now to add a Converter so I can get the clicked object from the eventargs. But when I add a converter it is executed when the page appears and not when the click is executed. Also I do get the bound command instead of the click arguments.
Greeting,
I'm developing an apps for Windows Phone 8.1 and face some problem with ListView.
I wanted to place a button for the FIRST item in ListView, but it seem like I can't align center the button.
Below is the code I use currently:
<ListView>
<Button Content="Jio!" Height="6" Width="362"/>
<ListViewItem Content="ListViewItem"/>
</ListView>
Adding horizontalalignment='center' just wont work for the button.
The reason I want to do this is because I wanted the button to scroll together with the list, hence I'm placing it inside the ListView.
Please advice what can I do to achieve my purpose, thanks!
I recommend using the ListView.Header content to place such a button instead of adding it as a child directly.
<ListView>
<ListView.Header>
<Button ... HorizontalAlignment="Center" />
</ListView.Header>
</ListView>
By default, the ListViewItems are left-aligned. You will eventually have to replace their Template in order to center-align it (HeaderTemplate Property).
Hi, I have a problem using the MVVM pattern after I instantiate my view model in this way:
<phone:PhoneApplicationPage.Resources>
<local:DetailVM x:Key="DetailVM"/>
</phone:PhoneApplicationPage.Resources>
How do I know when this Page is Loaded?
You can use the Blend SDK and add an event trigger that triggers a command in your viewmodel.
include
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
in your xmlns includes, and then add a trigger for the Loaded event.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
The LoadCommand is simply a property that returns an ICommand. You should of course either set the DataContext of the page to your viewmodel, or set the source of the binding to the one in your resources.
I've managed to get the LongListSelector running through MVVM.
In other words the ItemSource is set through a property on my viewmodel.
But for some weird reason, I can't seem to be able to 'bind' the SelectedItem of the LongListSelector... I'm not getting in the Set nor Get of the ViewModel property.
How is this done? And what should the 'type' of the SelectedItem on the ViewModel be? I thought the Type of the Class inside the Group?
My current xaml:
<silverlighttoolkit:LongListSelector x:Name="AlbumsList"
Background="Transparent"
ItemTemplate="{StaticResource ItemTemplate}"
GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}"
GroupItemTemplate="{StaticResource GroupItemTemplate}"
ItemsSource="{Binding GroupedAlbums}"
SelectedItem="{Binding SelectedAlbum, Mode=TwoWay}">
<silverlighttoolkit:LongListSelector.GroupItemsPanel>
<ItemsPanelTemplate>
<silverlighttoolkit:WrapPanel />
</ItemsPanelTemplate>
</silverlighttoolkit:LongListSelector.GroupItemsPanel>
</silverlighttoolkit:LongListSelector>
Use the SelectionChanged event. Either though a EventToCommand behaviour, or a attached behaviour.
I have a list view, on a panoramic control. I've also created an event for MouseLeftButtonUp however I find that when scrolling between the panorama items the MousLeftButtonUp is triggering (it makes sense why but it is unexpected from a user perspective).
Is there any way to create a click event for a list? Or add a behavior that simulates that?
Checkout the Tap gesture from the Gesture service that's part of the toolkit.
WP7 Tip of the Day: Silverlight Toolkit: Gestures
<ListBox Height="100" HorizontalAlignment="Left" Margin="12,186,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" >
<Controls:GestureService.GestureListener>
<Controls:GestureListener Tap="GestureListener_Tap">
</Controls:GestureListener>
</Controls:GestureService.GestureListener>
<ListBoxItem Content="1"/>
<ListBoxItem Content="2"/>
<ListBoxItem Content="3"/>
<ListBoxItem Content="4"/>
</ListBox>
and
public void GestureListener_Tap(object sender, GestureEventArgs e) {
System.Diagnostics.Debug.WriteLine("tap");
}
The listbox should already accept contact, so you can just fire the SelectionChanged event