c# - How do I change the Textblock value on my splash screen? -
i'm trying make animated splash screen app. have mainpage show popup has animation , textblock. i'd change text of textblock show status of loading, can't change it. ideas?
mainpage code
namespace animatedsplash { public partial class mainpage : phoneapplicationpage { backgroundworker preloader; popup splashpop; public mainpage() { initializecomponent(); splashpop = new popup(){isopen = true, child = new splash() }; preloader = new backgroundworker(); runpreloader(); } private void runpreloader() { preloader.dowork += ((s, args) => { thread.sleep(10000); }); preloader.runworkercompleted += ((s,args) => { this.dispatcher.begininvoke(()=> { this.splashpop.isopen = false; }); }); preloader.runworkerasync(); } } }
splash xaml
<phone:phoneapplicationpage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:microsoft.phone.controls;assembly=microsoft.phone" xmlns:shell="clr-namespace:microsoft.phone.shell;assembly=microsoft.phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:system.windows.interactivity;assembly=system.windows.interactivity" xmlns:ec="clr-namespace:microsoft.expression.interactivity.core;assembly=microsoft.expression.interactions" xmlns:eim="clr-namespace:microsoft.expression.interactivity.media;assembly=microsoft.expression.interactions" xmlns:local="clr-namespace:animatedsplash" mc:ignorable="d" d:designwidth="480" d:designheight="800" x:class="animatedsplash.splash" orientation="portrait" shell:systemtray.isvisible="false"> <phone:phoneapplicationpage.resources> <storyboard x:name="load"> <doubleanimationusingkeyframes storyboard.targetproperty="(uielement.rendertransform).(compositetransform.rotation)" storyboard.targetname="image"> <easingdoublekeyframe keytime="0" value="-180"/> <easingdoublekeyframe keytime="0:0:1" value="0"/> <easingdoublekeyframe keytime="0:0:2" value="180"/> </doubleanimationusingkeyframes> </storyboard> </phone:phoneapplicationpage.resources> <phone:phoneapplicationpage.fontfamily> <staticresource resourcekey="phonefontfamilynormal"/> </phone:phoneapplicationpage.fontfamily> <phone:phoneapplicationpage.fontsize> <staticresource resourcekey="phonefontsizenormal"/> </phone:phoneapplicationpage.fontsize> <phone:phoneapplicationpage.foreground> <staticresource resourcekey="phoneforegroundbrush"/> </phone:phoneapplicationpage.foreground> <i:interaction.triggers> <eim:storyboardcompletedtrigger storyboard="{staticresource load}"> <eim:controlstoryboardaction storyboard="{staticresource load}"/> </eim:storyboardcompletedtrigger> <i:eventtrigger> <eim:controlstoryboardaction storyboard="{staticresource load}"/> </i:eventtrigger> </i:interaction.triggers> <!--layoutroot root grid page content placed--> <grid x:name="layoutroot" background="transparent"> <!--titlepanel contains name of application , page title--><!--contentpanel - place additional content here--> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"/> </grid.rowdefinitions> <image margin="0" grid.row="1" source="/media/splashbg.jpg" stretch="fill" d:islocked="true"/> <image x:name="rotator" margin="96,288,184,312" grid.row="1" source="media/splashpin.png" stretch="fill" d:islocked="true"/> <image x:name="image" margin="142,305,0,370" grid.row="1" source="media/pinload.png" stretch="fill" horizontalalignment="left" width="75" rendertransformorigin="0.838,0.504"> <image.rendertransform> <compositetransform/> </image.rendertransform> </image> <textblock x:name="preloader_percentage" margin="178,354,0,0" grid.row="1" textwrapping="wrap" text="100" verticalalignment="top" rendertransformorigin="0.5,0.593" textalignment="right" horizontalalignment="left" width="35" fontfamily="segoe wp semibold" height="27"/> <textblock margin="213,354,0,0" grid.row="1" textwrapping="wrap" text="%" verticalalignment="top" horizontalalignment="left" width="16" fontfamily="segoe wp semibold" d:islocked="true"/> </grid> </phone:phoneapplicationpage>
how this:
in splash.xaml.cs have following:
public string progress { { return preloader_percentage.text; } set { preloader_percentage.text = value; } }
and in mainwindow.xaml.cs change code this:
preloader.workerreportsprogress = true; preloader.progresschanged += (sender, e) => { this.dispatcher.begininvoke(() => (this.splashpop.child splash).progress = e.progresspercentage.tostring()); };
then in worker method need call preloader.reportprogress() method several times. far know, should it.
note: there lot of design landmines here. i'd suggest getting code work, , can refactor later make cleaner , easier maintain.
Comments
Post a Comment