I promised before I'd try to get this code up somewhere. I've uploaded this entire example to github here. Please read the notes in the Readme about deployment, it requires signing the package with a certificate you've added to your trusted root stores.
The app I discussed in my previous post is fairly boring: all it does is present some text to the screen. I wanted it to do a little bit more to experiment with how events are attached to controls in WinRT. How about I make the text change color when the mouse hovers over it? Actually I shouldn't say mouse, I mean Pointer. In Xaml apps, mouse, keyboard, and touch events are all unified into a Pointer events so they all operate in similar ways. Anyway, it is a simple addition that makes the app more interesting.
WinRTs notion of events is a little different from VCL, and I think it'll be a welcome change. Events are handled with multicast delegates, similar to in C#. With any given event for any control, you could add multiple delegates to listen for that event. Each event has an add_* and a remove_* method to install or uninstall an event listener. For my Text, I'll be adding PointerEntered and PointerExited events. Both of these require a Windows.UI.Xaml.Input.PointerEventHandler, so I'll create a little delphi wrapper for that class.
type
TPointerEventHandler = class(TInspectableObject, PointerEventHandler)
private
FProc: TProc ;
public
constructor Create(Proc: TProc );
// PointerEventHandler methods
procedure Invoke(sender: IInspectable; e: IPointerEventArgs); safecall;
end;
{ TPointerEventHandler }
constructor TPointerEventHandler.Create(
Proc: TProc );
begin
FProc := Proc;
end;
procedure TPointerEventHandler.Invoke(sender: IInspectable; e: IPointerEventArgs);
begin
FProc(sender, e);
end;
This creates an instance of a handler, and stores of a reference to a procedure that should handle the event. That means the code for my event handler can still live in TDerivedApp, even though it's handed off to WinRT by this helper class. I've added an OnPointerEntered and OnPointerExited methods to my application class. In my OnLaunched event is where I actually hook the event handler up to the code:
procedure TDerivedApp.OnLaunched(args: ILaunchActivatedEventArgs);
var
insp: IInspectable;
element: Windows_UI_Xaml_IUIElement;
begin
// Get the IWindowStatics
OleCheck(RoGetActivationFactory(TWindowsString(SWindow), IWindowStatics, insp));
WinStatic := insp as IWindowStatics;
// Get an IXamlReaderStatics
OleCheck(RoGetActivationFactory(TWindowsString(SXamlReader), IXamlReaderStatics, insp));
ReaderStatic := insp as IXamlReaderStatics;
WinStatic.Current.Content := ReaderStatic.Load(TWindowsString(content)) as IUIElement;
FInner.OnLaunched(args);
// New code here: added event handlers for pointer enter and exit
insp := (WinStatic.Current.Content as IFrameworkElement).FindName(TWindowsString('Text'));
element := (insp as IUIElement);
element.add_PointerEntered(TPointerEventHandler.Create(self.OnPointerEntered));
element.add_PointerExited(TPointerEventHandler.Create(self.OnPointerExited));
WinStatic.Current.Activate;
end;
procedure TDerivedApp.OnPointerEntered(sender: IInspectable; e: IPointerEventArgs);
var
brush: ISolidColorBrush;
insp: IInspectable;
color: IInspectable;
begin
// Create a red brush
OleCheck(RoGetActivationFactory(TWindowsString(SSolidColorBrush), ISolidColorBrushFactory, insp));
OleCheck(RoGetActivationFactory(TWindowsString(SColors), IColorsStatics, color));
brush := (insp as ISolidColorBrushFactory).CreateInstanceWithColor((color as IColorsStatics).Red);
// Assign it to the text block
(sender as ITextBlock).Foreground := (brush as IBrush);
end;
I've omitted the code for OnPointerExited here; it's nearly identical to OnPointerEntered except it uses a white brush. Again, some of the code here, like creating a brush, is quite verbose and ugly; eventually class wrappers will make this look much nicer, similar to the C# and C++ projections that would alow this to look something more like:
sender.Foreground := Windows.UI.Xaml.Media.SolidColorBrush.Create(
Windows.UI.Xaml.Media.Colors.Red);
How looks result?
ReplyDeleteGreat Article
DeleteFinal Year Projects for CSE
JavaScript Training in Chennai
Project Centers in Chennai For CSE
JavaScript Training in Chennai
It is time on behalf of Microsoft to equate these reasons to hearten extra developers to erect cell phone apps by targeting Windows Phone 8. Poker Uang Asli,
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
ReplyDeleteSeputar Dunia
i like your article :) , Agen Bola Terpercaya
ReplyDeleteIf you are looking for buy used cars here we offer the good condition, examined, finest, tested and good maintain buy used cars in Meerut.
ReplyDeleteBuy Second Hand Cars in Meerut
very good article ^-^
ReplyDeleteDaftar Akun Bola
Bandar Togel Online
IDNPLAY POKER
Daftar Livepoker
Livechat Livepoker
Daftar Domino QQ
Daftar Bandar Ceme
Daftar Capsa Susun
Situs Judi Online Poker terpercaya I very easily understand the contents of your articles because it uses a language that is easy to understand
ReplyDeleteThanks for letting me share
ReplyDeleteTechfogg
Myskyflorist
Avriq
ReplyDeleteAvriq MAP
CCTV Camera
Pest control services
PC Optimization
CP Plus
Termite control services
Avriq
ReplyDeletePada permainan Poker Online, ada ber aneka macam meja jumlah pemain yang tersedia. Ada meja yang hanya untuk 3 pemain , 4 pemain dan bahkan sampai 9 pemain. Disini anda bisa pilih sesuai dengan keinginan anda apakah ingin bermain rame – rame atau hanya untuk sedikit pemain saja. Dan sudah banyak sekali orang yang mengemari Poker Online tersebut.
DOMINOQQ ONLINE
BandarQ Online
ReplyDeleteI think I need it. Thank you for update information. i like your blog.
فني صحي الكويت
نقل عفش بالكويت
شركة نقل عفش بحائل
ReplyDeleteشركة نقل اثاث بحائل
نقل عفش بحائل
نقل اثاث بحائل
شركة نقل عفش بخميس مشيط
شركة نقل اثاث بخميس مشيط
نقل عفش بخميس مشيط
نقل اثاث بخميس مشيط
just information we only provide information for those who need it cara menggugurkan kandungan
ReplyDeleteA. obat telat datang bulan
B. posisi berhubungan agar cepat hamil
C. makanan dan minuman agar cepat hamil
D. panduan agar cepat hamil
E. cara agar cepat hamil
F. cara agar cepat hamil setelah selesai haid
G. cara alami untuk segera mendapat kehamilan
Packers and Movers Pune Provide High Quality ***Household Shifting, Home/Office Relocation, Insurance, Packing, Loading, ###Car Transportation Service Pune and High experiences, Top Rated, Safe and Reliable, Best and Secure Packers and Movers Pune Team List. Get ✔✔✔ Affordable Rate Charts and Compare Quotation and Save Money and Time .
ReplyDeletePackers And Movers Pune
ReplyDeleteشركة كشف تسربات بالمدينة المنورة
افضل شركة غسيل خزانات بالرياض
شركة تنظيف مكيفات بالرياض
و افضل شركة تنظيف منازل بالطائف
Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges. Packers And Movers Bangalore
ReplyDeletevisit to our website for Hp printers help
ReplyDeleteHP Printer support phone number
hp printer customer care number
hp printer technical support number
hp service centre USA
hp store contact number
hp service centre near me
HP Printer tech support phone number USA
شركة النجوم لخدمات التنظيف
ReplyDeleteشركة تنظيف خزانات بالرياض
شركة تنظيف بالرياض
شركة تنظيف شقق بالرياض
It is possible to read and compile ideas and make a table clean, organize and arrange according to your priorities and your home cleaning needs. Ahsa.
We are popular as Florist Service in Gurgaon from last 10 Years, we also offers fresh flowers cakes and latest gifts across Gurgaon. Send flowers online and Offline from flower shop for your loved ones and available for corporate gifting with fastest delivery.
ReplyDeleteFlorist Service in Gurgaon
Online Florist Services in Gurgaon
packers and movers baner
packers and movers balewadi
packers and movers ravet
packers and movers bhosari
packers and movers telegaon
packers and movers magarpatta
packers and movers aundh
ReplyDeleteEach of the women associated with our agency is strictly professional when it comes to rendering her services to her clients.Russian Call Girls in Gurgaonhere at our escort agency make sure that their talents are such that they will never fall short of giving the best of services to their clients. Check our other Services...
Russian Escorts in Gurgaon
Call Girls in Faridabad
Escorts in Faridabad
Escorts Service in Faridabad
Russian Escorts in Faridabad
Sahabatpoker, Agen Domino99, Poker Online, Bandarq Terbaik Di Asia
ReplyDelete
ReplyDeleteEach of the women associated with our agency is strictly professional when it comes to rendering her services to her clients.Independent Call Girls in Goahere at our escort agency make sure that their talents are such that they will never fall short of giving the best of services to their clients. Check our other Services...
Goa Call Girls Service
Call Girls in Hotels in Goa
Escorts in Goa
Escorts Service in Goa
Housewife Escorts in Goa
Hi Profile Escorts in Goa
Air Hostess Escorts in Goa
Call Girls In Goa
Escort services in nasirabad
ReplyDeleteEscort services in Churu
Escort services in Bhilwara
Escort services in Jaisalmer
Escort services in Guwahati
Have you ever heard of celeb networth - the famous website for celebrities information?
ReplyDeleteNice Blog ! i have seen that u have written a good Blog and way of expression is Awsome..
ReplyDeleteThankyou @ Packers and Movers Ahmedabad
Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.# @ Packers and Movers Ahmedabad
ReplyDeletePackers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges. @ Packers And Movers Bangalore
ReplyDeleteGreat article thank you!
ReplyDeleteI'm a beginner in programming, star to working with blog page creation and website design, initial stage its difficult to me, article like this help me to improve.
one our blog I designed is Tips for Packing and Moving Kitchen Items
Mua vé tại đại lý vé máy bay Aivivu, tham khảo
ReplyDeletechuyến bay từ singapore về hà nội hôm nay
vé máy bay daklak đi hà nội
đặt vé máy bay hà nội sài gòn vietjet
ve may bay di cam ranh
vé máy bay từ mỹ về việt nam hãng ana
Connect for beautiful and hot girls entertaining services
ReplyDeleteDubai Escorts
call girls in Dubai
Get Packers and Movers Kolkata List of Top Reliable, 100% Affordable, Verified and Secured Service Provider. Get Free ###Packers and Movers Kolkata Price Quotation instantly and Save Cost and Time. ✔✔✔Packers and Movers Kolkata Reviews and Compare Charges for household Shifting, Home/Office Relocation, ***Car Transportation, Pet Relocation, Bike SHifting @ Packers and Movers Kolkata
ReplyDeleteExcellent Blog. I really loved it @ low Cost Packers Movers in Kochi
ReplyDeleteThe quality of international transport 3.31. This indicates a satisfactory performance - the services are adequate, the prices are not too high, and usually match the quality exactly, although there is still room for improvement. http://www.confiduss.com/en/jurisdictions/bulgaria/politics/
ReplyDeleteThank you The visitors travelling to Kenya from Canada need to apply for visa to Kenya online. That offers them fast and secure visa services. You also can check the al information regarding to visa here to get in the Kenya.
ReplyDeleteWow.. Very informative article thanks for sharing please keep it up.. Foreign travelers can pay the Indian e visa fee with a secure network and the Indian visa fee for US citizens is different in case of emergency.
ReplyDelete