on enter event
-
Sunday, August 12, 2012 11:02 PM
I'm trying to run code to open a modal screen when the user tabs or clicks into a field.
I have similar even cose working when a field value is changed usign the begininvoke and INotifyPropertyChanged.propertyChanged
code, so need similar code for "enter" rather than "change"
Here is my Change code:
Private Sub UserParameters_SelectionChanged() ' catches the field that has the focus on the screen Dim selectedItem = Me.UserParameters.SelectedItem If (selectedItem Is Nothing) Then Return Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke _ ( Sub() RemoveHandler DirectCast(selectedItem, INotifyPropertyChanged).PropertyChanged _ , AddressOf PropertyChanged AddHandler DirectCast(selectedItem, INotifyPropertyChanged).PropertyChanged _ , AddressOf PropertyChanged End Sub ) End Sub Private Sub PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) 'ShowMessageBox("param 7 from within change = " & clsCommonfunctions.fncParamDate(7, "-All-", "err")) Select Case e.PropertyName Case "CurrentUserValue" If Me.UserParameters.SelectedItem.CurrentUserValue = "" Then entityWindow.AddEntity() Else entityWindow.ViewEntity() End If End Select End SubThanks
Grant
All Replies
-
Monday, August 13, 2012 1:50 AMModeratorAll I can say is that it's a very "bad" idea to be popping up modal windows when someone enters, or clicks into, a control. It would be very "jarring" experience for the users.
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer" By doing this you'll help people find answers faster. -
Monday, August 13, 2012 3:41 AM
This isnt a fequently used data entry screen, its a configuration screen. I'd just prefer to make my modal window to edit the value be triggered off the user clicking into the field rather than having to click on a button next to it. I'll probably end up having to put code on the field anyway to tell them they cant edit it directly.
Grant
- Edited by NZTechworks Monday, August 13, 2012 3:41 AM
-
Monday, August 13, 2012 3:53 AMModeratorIn that case, why not use an editable grid?
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer" By doing this you'll help people find answers faster. -
Monday, August 13, 2012 4:40 AM
My screen is bound to the UserParameter entity, which has a primary key of ParamUID.
I have a second entity UserParamValue with a primary key of this table is ParamUID and UserID.
UserParamValue has a many to one relationship with UserParameter linked on ParamUID.
Each user can only have one value for each parameter, and I want to display a list of the current users parameters and the values (if previously entered).
So I need to be able to add/edit the value in the UserParamValue entity for the current user, when my screen is listing the records of the UserParam entity. I cant make my screen bound to the UserPAramValue entity, or it will miss any new parameters created that havnt got a user set value.
My workaround to not using WCF RIA is to add a calculated field in the UserParameter entity that gets the currentusers value from the UserParamValue entity. This then displays in my screen, but obviously I cant edit it directly. So I have modal window that opens the UserPAramVale entity for the current user and current parameter, so the user can add or edit the value corresponding to the parameter. This works fine and enable me to display a simple datagrid list of parameters, and the current users value. I just want to replace the command button that calls the modal window with a call when the user clicks into the value field on the datagrid.
Hope that makes sense?
Grant
-
Tuesday, August 14, 2012 2:56 AMModerator
>I'm trying to run code to open a modal screen when the user tabs or clicks into a field.
For opening a modal screen when the user tabs , you should popup the screen when the in the screen_created event.
For opening a modal screen when the user clicks into a field(I think it is a textBox custom control), you should get the the textBox as it is controlavailable.
Then register the focus event for the textbox
-
Tuesday, August 14, 2012 10:02 PM
Ok that set me on a different path and I found some more of Yanns code for the lostfocus event that looks like it might work assuming there is an equivalent gotfocus event!
this is what I now have
Public Class Setup_UserParamValue Private Sub Setup_UserParamValue_Created() ' filter for current user Me.CurrentUser_LocProp = Application.Current.User.Name entityWindow.Initialise() 'catch when user value control is clicked or entered Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke( Sub() AddHandler Me.FindControl("CurrentUserValue").ControlAvailable, AddressOf ControlName_ControlAvailable End Sub) End Sub Private Sub ControlName_ControlAvailable(sender As Object, e As ControlAvailableEventArgs) Dim control = CType(sender, Control) AddHandler control.gotFocus, AddressOf ControlName_GotFocus End Sub Private Sub ControlName_GotFocus(sender As Object, e As RoutedEventArgs) 'open modal window to edit If Me.UserParameters.SelectedItem.CurrentUserValue = "" Then entityWindow.AddEntity() Else entityWindow.ViewEntity() End If End Subhad to add imports system.windows.controls and system.windows.
Now getting following error on this line in my ...._created private sub
AddHandlerMe.FindControl("CurrentUserValue").ControlAvailable, AddressOfControlName_ControlAvailable
"The control 'Value' appears to be inside a collection. The ControlAvailable and ControlUnavailable events are not available for controls in a collection."
So do I need to make this code a separate class rather than a private sub within the public class for htis screen?
Cheers
Grant
- Edited by NZTechworks Tuesday, August 14, 2012 10:25 PM learnt some more
-
Wednesday, August 15, 2012 2:40 AMModerator
Hi,
>"The control 'Value' appears to be inside a collection. The ControlAvailable and ControlUnavailable events are not available for controls in a collection."
I was a little confused , Do the control in a grid?
As far as I know, If you want to register the focus event for the textbox in the grid, you might should create your own silverlight grid control in order to achieve your requirement.:
More,I suggest you to convert the sender to the target control.Dim control = CType(sender, TargetControl)
-
Wednesday, August 15, 2012 5:06 AMyes its in a datagrid.
-
Thursday, August 16, 2012 1:19 AMModerator
Hi,
As far as I know, If you want to register the focus event for the textbox in the grid, you might should create your own silverlight datagrid control in order to achieve your requirement.
For how to add a custom control I have created a sample for Accordian before, you can create one for Datagrid:
First, create a Silverlight Application named AccordionControl in your LightSwitch Solution And add the code below:
<UserControl x:Class="AccordionControl.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"> <toolkit:Accordion Height="278" HorizontalAlignment="Left" Margin="10,10,0,0" Name="accordion1" VerticalAlignment="Top" Width="378"> <toolkit:Accordion.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Id}"></TextBlock> </DataTemplate> </toolkit:Accordion.ItemTemplate> <toolkit:Accordion.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding Information}"></TextBlock> </DataTemplate> </toolkit:Accordion.ContentTemplate> </toolkit:Accordion> </UserControl>using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace AccordionControl { public partial class MainPage : UserControl { public Accordion MyAccordion { get { return accordion1; } } public MainPage() { InitializeComponent(); } } }Then build the Silverlight Application.
I create Info table with only Information property.
I create a InfoesListDetail Screen.
Add a Custom Control to your Screen,Add Reference and select AccordionControl Project.
Then Name the Custom Control to accordion
Then add some codes for your screen:
partial void InfoesListDetail_Created() { // Write your code here. this.FindControl("accordion").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(InfoesListDetail_ControlAvailable); } void InfoesListDetail_ControlAvailable(object sender, ControlAvailableEventArgs e) { (e.Control as AccordionControl.MainPage).MyAccordion.ItemsSource = this.Infoes; } }Then run the application and add some information.
You can see the screen as below:
-
Thursday, August 16, 2012 4:13 AMModerator
<rant>
Can I just point out, that it's best practice to be reacting to changes in the DATA, not trying to manipulate CONTROLS on a screen. This is one of the things that make MVVM such a good practice, separation of data from its presentation.
I know there are times when manipulating the controls on a screen is the only way to do what's required, & I wouldn't argue against that type of use. But the more your programming relies on presentation implementations, the less "portable" your application will be to any future presentation framework.
So in summary, what I'm trying to say is, react to changes in properties wherever possible, & only drop down to the level of the controls when it's the only way to achieve the goal.
</rant>
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer" By doing this you'll help people find answers faster. - Proposed As Answer by Paul Van Bladel Friday, August 17, 2012 8:02 AM
-
Friday, August 17, 2012 1:25 AMModerator
@Yann,
Yes , you are right. It's not a good practice.
I will try to find a more suitable solution for this issue
-
Tuesday, August 21, 2012 5:51 AMModerator
Thanks for that Otomii!
I wasn't meaning to have a go at you, or what you were saying. I just wanted to point out what's "best practice", so that new people don't get off on the wrong foot, writing complicated code to manipulate controls on screen, & then find out they have to do it all over again if the presentation technology changes.
I do acknowledge however, that there ARE times that you may have to do it the "manilupate controls" way, but only when you can't do it in response to changes in the bound data itself.
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer" By doing this you'll help people find answers faster.

