Dienstag, 8. Februar 2011

Events in Window Phone 7

Remark of mine as the beginner will be continuously improved.

1. Event happens only in main page, without involking from Control after running, e.g. Event about Timer "void OnTimerTick(object sender, EventArgs args)". The invoking factor comes from the code in MainPage.
public MainPage()
{
InitializeComponent();

DispatcherTimer tmr = new DispatcherTimer();
tmr.Interval = TimeSpan.FromSeconds(1);
tmr.Tick += OnTimerTick;
tmr.Start();
}

void OnTimerTick(object sender, EventArgs args)
{
txtblk.Text = DateTime.Now.ToString();
}

2.Event is invoked by Control during running the programm after the user operation. This type of event should be defined in XAML-File.
HorizontalAlignment="Center"
VerticalAlignment="Center"
ManipulationStarted="OnTextBlockManipulationStarted" />
The appropriate function is added in the code of MainPage.
e.g.
void OnTextBlockManipulationStarted(object sender,
ManipulationStartedEventArgs args)
{
TextBlock txtblk = sender as TextBlock;

Color clr = Color.FromArgb(255, (byte)rand.Next(256),
(byte)rand.Next(256),
(byte)rand.Next(256));

txtblk.Foreground = new SolidColorBrush(clr);

args.Complete();
}

(TO be continued...)

Keine Kommentare: