我想從C#中的代碼隱藏中以編程方式添加BottomAppBar。我做到了這樣做:以編程方式在C#中用按鈕添加BottomAppBar
1:增加了一個資源文件,其中包含一個網格,一個StackPanel和兩個按鈕的DataTemplate。
2:在我的BasePage.cs(派生自Page類)中,我定義了一個新的AppBar並將它的ContentTemplate設置爲在step1中創建的資源。
3:我從step2設置this.BottomAppBar = AppBar。
現在,將AppBar添加到從BasePage派生的所有頁面中。這工作正常。
問題:
我不能得到PointerPressed或從AppBar我的兩個元素觸發的任何其他事件。
我相信這是我很想念的東西。任何想法,任何人?
更新:下面添加的示例下載鏈接和我想要的是當單擊BottomAppBar(Page1和2)中的圖像時,它應該帶我到MainPage。
AppBar代碼
AppBar appbar = new AppBar();
appbar.Name = "BottomBar";
DataTemplate dt = Application.Current.Resources["BottomAppBarDT"] as DataTemplate;
appbar.ContentTemplate = dt;
this.BottomAppBar = appbar;
謝謝扎克。不,我現在沒有使用MVVM,但想要如果它適合我的應用程序。我會嘗試一下你的建議,並更多地關注MVVM。 – TrekStir
我知道你的想法和代碼文章:http://www.codeproject.com/Articles/391783/An-Address-Book-Application-Made-in-MVVM-For-Metro。我會上傳我的代碼。雖然我在按鈕上工作,但我也希望能在Image PointerPressed上工作。圖像不支持Command。 – TrekStir
你可以使用一個按鈕並創建一個模板,並且我確定可能有一個名爲「ImageButton」的在線...這是我在Google上找到的第一個結果。 http://www.michielpost.nl/PostDetail_72.aspx –