How can I set a property when an event happens? (selection changed on datagrid)
I have a datagrid, I would like to change the backgrund of the datagrid when the selection changed event is fired.
I can not use data trigger, because is in the case that I expected a value, but in this case is when change, to any value.
An option is to use an event trigger, but all the examples that I have found is to use with an actions, and I just want to set a property.
How could I do that?
I am using MVVM pattern, so I would like to avoid the use in code-behind.
Thank so much.
You could use an event trigger and implement your own TriggerAction<T> that sets the background property. There is an example of how to create a custom TriggerAction available here:
http://stackoverflow.com/questions/942548/setting-a-property-with-an-eventtrigger.
The following example sets the Background property of the DataGrid to a red SolidColorBrush when the SelectionChanged event is fired. It should give you the idea:
<DataGrid x:Name="dgrid"
xmlns:local="clr-namespace:WpfApplication22">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<local:SetPropertyAction PropertyName="Background" TargetObject="{Binding ElementName=dgrid}">
<local:SetPropertyAction.PropertyValue>
<SolidColorBrush>Red</SolidColorBrush>
</local:SetPropertyAction.PropertyValue>
</local:SetPropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
namespace WpfApplication22
public class SetPropertyAction : TriggerAction<FrameworkElement>
public string PropertyName
get { return (string)GetValue(PropertyNameProperty); }
set { SetValue(PropertyNameProperty, value); }
public static readonly DependencyProperty PropertyNameProperty
= DependencyProperty.Register("PropertyName", typeof(string),
typeof(SetPropertyAction));
public object PropertyValue
get { return GetValue(PropertyValueProperty); }
set { SetValue(PropertyValueProperty, value); }
public static readonly DependencyProperty PropertyValueProperty
= DependencyProperty.Register("PropertyValue", typeof(object),
typeof(SetPropertyAction));
public object TargetObject
get { return GetValue(TargetObjectProperty); }
set { SetValue(TargetObjectProperty, value); }
public static readonly DependencyProperty TargetObjectProperty
= DependencyProperty.Register("TargetObject", typeof(object),
typeof(SetPropertyAction));
protected override void Invoke(object parameter)
object target = TargetObject ?? AssociatedObject;
PropertyInfo propertyInfo = target.GetType().GetProperty(
PropertyName,
BindingFlags.Instance|BindingFlags.Public
|BindingFlags.NonPublic|BindingFlags.InvokeMethod);
propertyInfo.SetValue(target, PropertyValue);
For more information about how to hook up event triggers and handle events in MVVM, please refer to my blog post:
http://blog.magnusmontin.net/2013/06/30/handling-events-in-an-mvvm-wpf-application/
Please also remember to mark helpful posts as answer.
Similar Messages
-
How can I set it so when people ring my mobile, it...
How can I set it so when people ring my mobile, it rings me on skype?
I get 0 signal in my house but I have internet and I need to take calls badly.Hi kpet417,
If you want to add calendar and weather to be seen on Notification Center, then open that up and look at the bottom for the edit button to bring up options to add to it. Take a look at the article below for more information.
Mac Basics: Notifications keep you informed
https://support.apple.com/en-us/HT204079
Take it easy,
-Norm G. -
How can i set "Createdby" attribute When using Custom JheadStart Security
Hello
We do not use JASS for Authentication , please help us how can i set createtby attributes with jhs.username in application for any entity object?
thanksSee a similar question at History Attributes when using Custom Authentication Type
-
How can i set a password when i open mozilla firefox homepage
how can i set username and password to the homepage of mozilla firefox
hello saranghaekijenia, can i ask what you are trying to achieve by setting a password? maybe there is a better way...
-
How can I set the language when sending an e-mail with attachment - 'Html'?
"Character Broken"
I made an ALV program, and this convert to "HTML', and send an e-mail with this.
Used Process is:
DATA: gt_abaplist LIKE TABLE OF abaplist,
gt_html LIKE TABLE OF w3html,
doc_chng LIKE sodocchgi1,
objpack LIKE TABLE OF sopcklsti1 WITH HEADER LINE,
objhead LIKE TABLE OF solisti1 WITH HEADER LINE,
mail LIKE TABLE OF solisti1 WITH HEADER LINE,
reclist LIKE TABLE OF somlreci1 WITH HEADER LINE,
lv_line TYPE i.
DELETE FROM MEMORY ID '%_LIST'.
SUBMIT z_template
AND RETURN EXPORTING LIST TO MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = gt_abaplist
EXCEPTIONS
not_found = 1
OTHERS = 2.
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
TABLES
html = gt_html
listobject = gt_abaplist.
doc_chng-obj_name = 'URGENT'.
doc_chng-sensitivty = 'O'.
doc_chng-obj_descr = ' '.
doc_chng-obj_langu = '3'.
objhead-line = ' '.
APPEND objhead.
mail[] = gt_html[].
DESCRIBE TABLE mail LINES lv_line.
CLEAR: objpack.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = lv_line.
objpack-doc_type = 'htm'.
objpack-obj_descr = ' '.
objpack-doc_size = lv_line * 255.
objpack-obj_langu = '3'.
APPEND objpack.
CLEAR: reclist.
reclist-receiver = 'e-mail address'.
reclist-rec_type = 'U'.
APPEND reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
object_header = objhead
contents_bin = mail
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
SUBMIT rsconn01 AND RETURN.
I want to show this by "Japanese".
But the character is broken.
LIke This:
u01D1u072C u0205| u0205u072C u0508 QC u04B90m
How can I set the language? How can I solve "Charancter Broken" ?
Plesse, let me know.
Thank you so much.
Edited by: Jaime White 999 on Nov 21, 2011 8:45 AM
Edited by: Jaime White 999 on Nov 21, 2011 8:46 AMHi Jaime,
Are you saying, you are getting junk characters in the email attachment? Then pls check the following. Since you want to send Japanese fonts, please pass language 'J' in both objpack-obj_langu = '3' & doc_chng-obj_langu = '3' instead of '3' please replace it with 'J'.
Another thing which you may have to check is the SCOT device type. As I understand from my basis colleague, this may also affect your attachment fonts since the emails are sent through SCOT. Go to transaction SCOT-> Settings-> Device types for format conversion. Check whether wrong device type is defined for Japanese there. Hope this helps
Regards,
Gokul -
How can I set the CS5 to Intuos Pro Large for changing brush size and opacity and others?
How can I set together to my PS5 or Ps6 in order to change brush size and opacity at the Intuos Pro Large?
Nachricht geändert durch Orhan TarmanThe MTU setting on the interface is the layer 3 packet size. In this case, the MTU is set to 1500, but the largest frame size transmitted on the interface (including layer 2 headers) is 1516. It sounds like you are experiencing another problem at the LES.
-
This question could just as well go to the iCloud on my Mac community...
I put 'I' in the topic for brevity but it's actually my wife who gets emails every time either of us adds or edits events, whether we do it in iCal on either of our Macs or in Calendar on our iOS devices. Presumably this is to do with a setting in iCloud somewhere, but I've searched high and low and can’t find it. I've also compared settings on our Macs and phones and can't find anything that could be the culprit. It's driving her nuts!
For more information, we share all our calendars so that either of us read and write any of them, and we're both on iOS 5.1 on our iPhones (hers is a 3GS, mine's a 4), and we're both on Mac OS X 10.7.3 Lion (2010 27" iMac and 2011 MacBook Pro respectively).this seems to be a new "bug" on iCloud. It's happened to many users (judging by the posts here). My wife and I have one shared calendar and we've been happily using it without the email problems (because I had set iCloud NOT to email us whenever an event changed - this was done at icloud.com, a setting there). Recently we began getting emails. I suspect a change in iCloud that was in error, because I just checked my setting and the option to have an email sent when an event changes is not checked.
-
How can i set the values to text box by selecting from drop down list.
hi ,
i am using struts and jsps. i have a dropdown list of names(getting the values of names from database), i want to get address and phone number of that selected one.how can i get that?Hi swarupa,
Well My advice in this senario wud Be
Either U can make Use of XmlHttp Object through javascript(AJAX way).
Or U need to Maintain the State of the entire form and then refresh the page to get those results....
just for U r reference i am attaching a link which was programmed using ASP @ server side and which made use of XmlHttp Object.....
http://www.w3schools.com/ajax/ajax_database.asp
Just try to simulate the samething in your own way....
REGARDS,
RAHUL -
i want my mac to be the controller of the emails on my iphone 4s and ipad hd---how do i do this?
That is how Time Machine works.
It is not going to keep files you delete from your computer forever.
But you haven't stated how they are stored on the TC.
If you copy files to the TC they can be stored long term.. or use another type of backup software.
See Q3 here about storing data and TM on the TC.
http://pondini.org/TM/Time_Capsule.html -
IPhoto 8.1.2 how can you set a password on an event or album?
I am downloading pictures from my iphone 4 to my iphoto on my mac and I wanted to set a password on a certain group of pictures and was wondering how to do that for the iPhoto 8.1.2 version.
You can't. It's not a feature of iPhoto.
For photos you want to hide from Mommy, put them in a Library stored on an encrypted disk image.
Regards
TD -
My husband and I have been sharing an I cloud account. He can't update his phone due to our shared account. I want to get him a new account and was told to delete the current I cloud account off his phone and just create a new one. The problem is that it wants to keep accessing the old one. I don't want my I cloud account changed. I don't know what to do. Any advice?
Did he have find my iPhone enabled under that iCloud account? If so, add the account back to his phone. Then in the iCloud account settings, disable find my iPhone first (you will be prompted for your password), then remove the account.
Now you can create or add a new iCloud account to it using his own AppleID.
Alternatively, you could log in to your www.icloud.com account in a web browser. Using the find my iPhone app there, remove his iPhone from your list of associated devices (he will have to power his iPhone off for you to do that).
After his iPhone is set up for his own iCloud account, on your iPhone, go to
settings->iCoud->Storage & Backup->Manage Storage and delete his iPhone's backup file to make more room on your own iCloud storage account. -
How can I set the page that will open, when I open a new tab, to be the same as the homepage?
An app changed it to some other search engine, before installing the app, I the tab that would open was the homepage I set.
In my case it is Google, and I want my new tabs to open on Google like they did before the installation.
thank you,
Asaf Privman.You can middle-click or Ctrl left-click the Home button on the Navigation toolbar to open the Home page in a new tab.
You can look at one of these extensions:
* NewTabURL : https://addons.mozilla.org/firefox/addon/newtaburl/
* New Tab Homepage : https://addons.mozilla.org/firefox/addon/new-tab-homepage/ -
I have bought an iPhone4 and to be able to use it for the first time I connected into a friends' itunes. Now when I want to buy itunes stuff on the phone it asks me her password. How can I set up again my itunes account?
Now I also have a macbook where I can sync my iphone but it doesn't allow mefirst of all only sync it with 1 computers itune account
second settings->general->store click the appleID box with her appleID in it and log out -
How can I set up lightroom 5, so that it becomes my main / default editing program & that when I insert my sd card into the mac lightroom starts instead of iPhoto .
Thanks. Im new to apple, which preference?
Sent from my iPhone -
How can I set up my email so when I delete mail from my Mac it deletes from my iPhone as well?
How can I set up my email so when I delete mail from my Mac it deletes from my iPhone as well?
That is a function of your email account, if it is an Imap account it will sync, if it's a POP account, it won't.
Who provides your email.
Maybe you are looking for
-
How do I analyze Console's description of crashes?
Since I upgraded to system 10.4.7 I have experienced frequent crashes. Thanks to DisK Warrior I have been able to recuperate, but crashes are happening with some regularity (every week at least once). I can't figure out the reason. Here is a copy of
-
RENN item not flowing in return sales order automatically
Hi all, When i add RENN in item category proposal for copy control of billing doc to sales doc(YDRE to YDF2) where YDRE is return and YDF2 is outbound billing. So when I create a return order with reference to invoice will the free good item flow aut
-
Looking for a new work flow...
I am about to get a new macbook 13inch (at the moment i use a 1st gen 17inch intel) I will get a new monitor for the home but want something very portable. Right, at the moment i store all my Aperture files on an external firewire drive and back up t
-
istalling third party instruments.. i have tried to go to application support and putting them into the sampler but they are still not showing up.. can someone help me
-
OIM 11g - Limiting support users to assign roles to correct users
We have OIM 11.1.1.5.0 and support a couple of third party organizations with delegated administration. Admins in OrgA have an admin role AdminRoleA which allows them to assign UserRoleA to their users. Similarly, admins in OrgB are given AdminRoleB