2010-03-17 36 views
-1

我在使用Silverlight頁面中的自定義UserControl時遇到問題。用戶控件通常是一個包含較小矩形的矩形。 我想在Silverlight MainSite中使用UControl。 我實現了對鼠標按鈕的小矩形的方法稱爲在這裏Button1的:用矩形作爲按鈕的Silverlight UserControl

public void Button1_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) 
    { 
    MessageBox.Show("Hello"); 
    } 

如何我可以用它從MainSite?從那裏我只能實現一種方法,如:

private void ImportedControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     firstLeaf.Button1_MouseLeftButtonDown(sender, e); 
    } 

我不能實現Button1的方法。

我該如何處理這項工作? 幫助:)

+0

我真的不明白你在問什麼。 – 2010-03-17 15:28:46

+1

我做了一個用戶控件,我放了一個矩形。該矩形稱爲Button1,並用作按鈕。在項目中使用此控件時,我無法引用Button1或klick選項。 – Rafal 2010-03-18 14:49:54

+0

我會補充說控制是在Expression Blend工具中完成的,但它仍然沒有關係 – Rafal 2010-03-18 14:50:55

回答

0

我仍然不確定我是否理解這個問題,但讓我來回答一個問題。你爲什麼不使用一個真正的按鈕,只是用一個矩形模板?通過這種方式,您可以獲得實際擁有按鈕的所有好處,同時使其看起來像一個矩形,包括Click事件。

這是Scott Guthrie在control templating with a button上做的一篇文章。