![](/img/trans.png)
[英]How to create datacontextchanged event in windows phone 8 silverlight
[英]How can I make an event for the Layout (exept some elements) in SilverLight or Windows Phone
我有一個帶有兩個文本框的表單,單擊該布局(例如此文本框)時,會發生什么事件以及如何使用它來執行操作? 因此,當我單擊文本框時,此事件不起作用。 當我單擊布局的其他部分(例如表單上的文本框)時,它應該可以工作
我做了類似的事情。 在后面的代碼中,我使用了以下代碼:
layoutRoot.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler((s, e) =>
{
//In this case, don't focus.
if (RecieveFocus != null &&
e.OriginalSource is Textbox &&
((e.OriginalSource as Textbox).Tag == "DONT FOCUS")
{
//do nothing, or whatever you want
}
else if(RecieveFocus != null)
RecieveFocus(this, new EventArgs());
}), true);
您可以檢查文本框是否是您的原始來源,如果是,則不要執行其他操作。 Add Handler的最后一個布爾值true表示處理標記為已處理的事件。
我創建了一個稱為RecieveFocus的事件,即使在我的布局根目錄上單擊了任何內容,我都會處理並提出該事件,但在這種情況下,帶有“ DONT FOCUS”標簽的文本框除外
您可以在頁面的主網格上設置MouseLeftButtonUp-event。 像這樣:
<Grid x:Name="LayoutRoot" Background="Transparent" MouseLeftButtonUp="LayoutRoot_MouseLeftButtonUp">
事件看起來像這樣:
private void LayoutRoot_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//Do something
}
我在具有兩個TextBoxes和一個Checkbox的頁面上對此進行了測試,並且可以正常工作。 除了TextBoxes和CheckBox之外,我單擊的所有地方都會引發該事件。 希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.