2014-03-07 35 views
0

在Windows應用商店應用中,我創建了一個UserControl來封裝和重新使用代碼隱藏和佈局XAML。如何處理UserControl中按鈕的Click事件 - Windows 8應用程序?

「ForumItem.xaml」用戶控件:

<UserControl> 
    <Grid> 
     <Button x:Name="YesButton" Content="Button" Grid.Row="1"/> 
     <Button x:Name="NoButton" Content="Button" Grid.Column="1" Grid.Row="1" /> 
    </Grid> 
</UserControl> 

我創建十個項目形成我的用戶,然後將其在添加到網格代碼隱藏MYPAGE:

Grid grid = new Grid() 
for (int i = 0 ; i<10 ; i++) 
{ 
    ForumItem sss = new ForumItem(); 
    RowDefinition row = new RowDefinition(); 
    row.Height = new GridLength(1, GridUnitType.Star); 
    grid.RowDefinitions.Add(row); 
    Grid.SetRow(sss, flag); 
    grid.Children.Add(sss); 
} 

我要處理請點擊事件爲兩個按鈕在十個用戶控件中,我真的很感激任何幫助。謝謝 。

回答

0

在UserControl中聲明NoClickYesClick事件。 它們分別應該爲「是」和「否」按鈕執行處理程序。 將它們暴露在UserControl中,並在填充網格時將它們連接起來。

+0

這工作很好! ,我向上帝發誓,我嘗試了這個解決方案一千次,但只有這一次工作! 謝謝你,但要設置這是一個正確的答案,你能回答我的問題的第二部分:我知道現在怎麼可以處理YesButton Click事件。我怎麼知道在十個按鈕中點擊了哪個YesButton? –

+0

你是什麼意思「暴露UserControl?」這是如何完成的? –

相關問題