![](/img/trans.png)
[英]How to capture tap event on specific button in user control from main form
[英]How to Get Tap Event from User Control in Page
希望這個問題有意義。 我想做的是在用戶控件中放置一個Ellipse
(或樣式化的按鈕,使其看起來像一個帶有圖標的橢圓形),該控件動態地填充在我的代碼后面,然后能夠確定何時在用戶身上點擊了Ellipse
控件,並執行與單擊用戶控件時不同的操作。我正在使用的示例實際上來自經過一些調整的Nokia Imaging SDK示例。
PhotoThumbnail.xaml //用戶控件
<Ellipse Grid.Row="0" Grid.Column="1" Stroke="LightGray" StrokeThickness="3"
VerticalAlignment="Top" HorizontalAlignment="Right" Width="50" Height="50" Margin="7"/>
PhotoThumbnail.xaml.cs
public event PropertyChangedEventHandler PropertyChanged;
public PhotoThumbnail()
{
InitializeComponent();
DataContext = this;
}
Page.xaml.cs
//Creae PhotoThumbnail
PhotoThumbnail photoThumbnail = new PhotoThumbnail()
{
..
};
photoThumbnail.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
{
// do something
};
panel.Children.Add(photoThumbnail);
}
}
}
}
上面的photoThumbnail.Tap
事件執行一個操作,但是如何確定用戶是否在PhotoThumbnail
UserControl
上點擊了Ellipse
而不是控件本身?
我剛剛在Page.xaml.cs中添加了以下內容,並在用戶控件x:Name="EditableEllipse"
中將其命名為Ellipse。
photoThumbnail.EditableEllipse.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
{
if (sender != null)
{
.. do something ..
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.