XAML中的自定义事件对我的用户在Windows Phone 7 [英] Custom events in XAML on my UserControl on Windows Phone 7
问题描述
我做在Windows Phone 7的一个用户控件,我想,当用户点击OK按钮其他XAMLs它正在使用我的用户可以能够添加与该事件。
I'm making a UserControl in Windows Phone 7 and i want that when the user clicks on an Ok button the other XAMLs which are using my UserControl can be able to add an event related to that.
使用是这样的一个例子:
Using an example it's like this:
我有我的MainPage.xaml中,我用我的用户那里,所以它的东西像
I have my MainPage.xaml and i'm using my UserControl there, so it's something like:
<local:MyUserControl Canvas.Top="0" x:Name="lSelector" Width="480" Height="800" Value="0000"/>
值就是这样我创建了一个DependencyProperty的。我要的是能够做这样的事:
Value is just a DependencyProperty that i created. What i want is to be able to do something like this:
<local:MyUserControl Canvas.Top="0" x:Name="lSelector" Width="480" Height="800" Value="0000" ValueChanged="lSelector_ValueChanged"/>
我怎么能做到这一点?
how can i do that?
推荐答案
事件添加到您的用户控件像下面的代码,它会看起来像正常事件
Add event to your UserControl like code below and it will appears like normal event
public partial class UserControl1 : UserControl
{
public delegate void ValueChangedEventHandler(object sender, EventArgs e);
public event ValueChangedEventHandler ValueChanged;
public UserControl1()
{
// Required to initialize variables
InitializeComponent();
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (ValueChanged != null)
{
ValueChanged(this, EventArgs.Empty);
}
}
}
然后,只需订阅它
private void UserControl1_ValueChanged(object sender, System.EventArgs e)
{
// TODO: Add event handler implementation here.
}
这篇关于XAML中的自定义事件对我的用户在Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!