How to get a WPF command to execute on row double click of the Infragistics WPF datagrid? - xamdatagrid

I have a WPF XamDataGrid (I'm using the MVVM pattern, xaml below) and I need it to show the record details in another window when the user double clicks on a row. I have the command which gets the job done, but I don't know how to fire it up as I do with buttons. I want to be able to execute the command when the user double clicks a row, so I need to send the double clicked row (or its ID) as a parameter to the comand. Is it possible?
<igDP:XamDataGrid DataSource="{Binding SomeList}">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout >
<igDP:FieldLayout.Fields>
<igDP:Field Name="ObjectId" Label="Id" Width="Auto"/>
<igDP:Field Name="Description" Label="Object Description" Width="Auto"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

I use MVVM pattern too and write such as:
<igDP:XamDataGrid ItemsSource={Binding Path=StaffList, Mode=OneWay}>
...
<igDP:XamDataGrid.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding Path=EditStaffCommand, Mode=OneWay}"
CommandParameter="{Binding Path=DataItem}"/>
</igDP:XamDataGrid.InputBindings>
...
</igDP:XamDataGrid>
Where EditStaffCommand and StaffList - properties from view model

Take a look at Attached command behaviours (http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/). They allow to bind commands to events.

You can create a behavior to add a binding between your ViewModel’s Command and the Double Click event of the Grid.
See the following post for more information:
http://blogs.infragistics.com/forums/p/67749/343013.aspx#343013

Related

Cancelcommand is not working in sfdatepicker in xamarin forms

I want normal cancel functionality on cancel button click of sfdatepicker footer, I am trying to achieve it by binding command but it is not working. Could any one suggest me any solution for that ?
You can use code like below:
<datePicker:SfDatePicker.FooterView>
<Grid>
<Button Text="Ok"
x:Name="footerViewButton"
Clicked="footerViewButton_Clicked"/>
</Grid>
</datePicker:SfDatePicker.FooterView>
Created in this way, and then create the corresponding method in the ViewModel to achieve logical operations.

ReactiveUI bind to DataTemplate

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.

How to add a button to first item in ListView

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).

Change Content of a ListFooterTemplate of LongListSelector

Follow -up to the answer of this question :Add a Load More Button at the end of ListBox without losing Virtualization?
With this example :
<toolkit:LongListSelector ItemsSource="{Binding Items}">
<toolkit:LongListSelector.ListFooter>
<Grid>
<Button x:Name="btnReadMore" Content="ReadMore"/>
</Grid>
</toolkit:LongListSelector.ListFooter>
Is there a way to change his Content by the C# ? (= "ReadMore" and when the itemsource=0 "go back") thank you !
You can bind the value of the Content property to some ViewModel property. This is the best way IMHO:
You would also bind the Command property to some ViewModel command and this will ensure that you correctly set the caption and handle the result.
But beware, you are not supposed to have a button saying "Go Back" which, when pressed, acts as a hardware back button. You are not supposed to emulate such system functionality.

dynamically create custom buttons in code wp7

i have a button control in code as
Button>
<Button.Content>
<StackPanel Orientation='Horizontal' >
<TextBlock Text='{Binding ramDay, Mode=TwoWay}' Margin='0,-18,0,0' Style='{StaticResource PhoneTextTitle1Style}'/>
<TextBlock Text='{Binding enDay, Mode=TwoWay}' Margin='15,10,0,0' Style='{StaticResource PhoneTextTitle2Style}'/>
</StackPanel>
</Button.Content>
</Button>
but i want to create as many buttons as user want with different values of textboxes as user want them. but i am unable to find any way, kindly help me.
thanks
Create a custom user control in you project by using this code there. Thereafter in your mainPage in the code behind add the userControl dynamically to the grid present on the UI in a for-loop or any other method which you find suitable to your situation.

Resources