EventBindingExample
EventBindingExampleWeb
MainPageViewModel
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.ComponentModel; namespace EventBindingExample.ViewModels { public class MainPageViewModel : INotifyPropertyChanged { // Implementation of INotifyPropertyChanged interface public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } // Properties private string displayText; public string DisplayText { get { return displayText; } private set { displayText = value; NotifyPropertyChanged("DisplayText"); } } // Public methods public void WndSizeChanged(object sender, SizeChangedEventArgs e) { DisplayText = "Window height: " + e.NewSize.Height.ToString() + " Window Width: " + e.NewSize.Width.ToString(); } } }
public
DisplayText
string
WndSizeChanged
SizeChanged
SizeChangedEventArgs
<UserControl x:Class="EventBindingExample.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" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d" FontFamily="Verdana" FontWeight="SemiBold"> <i:Interaction.Triggers> <i:EventTrigger EventName="SizeChanged"> <ei:CallMethodAction MethodName="WndSizeChanged" TargetObject="{Binding}" /> </i:EventTrigger> </i:Interaction.Triggers> <Grid x:Name="LayoutRoot" Background="White" VerticalAlignment="Center" HorizontalAlignment="Center"> <TextBlock Foreground="Green" Text="{Binding Path=DisplayText}" /> </Grid> </UserControl>
No hay comentarios:
Publicar un comentario