2012-12-21 16 views
5

我做了100左右Hubtiles我的應用程序中啓動的瓷磚,我希望他們能夠讀取XML文件時,它們被挖掘,用戶能夠「腳開始」的在應用程序外面的屏幕上顯示所需的Hubtile。的Windows Phone 7針從一個應用程序

每Hubtile讀取不同的XML文件,並必須能夠被固定到開始。

我知道代碼到別針把它啓動了,我知道的代碼,使其讀取XML,但也有100瓦,這將是編碼和複製/粘貼的多條線路。

這是我的一個瓷磚的代碼可以從應用程序到流行和被固定到開始XAML:

<toolkit:HubTile Name="Monday" Title="Monday" Source="Days\Weekdays\Monday.png" Margin="15" Tap="day_Tap"> 
    <toolkit:ContextMenuService.ContextMenu> 
     <toolkit:ContextMenu> 
      <toolkit:MenuItem Name="monday" Header="pin to start" Tap="monday_Tap"/> 
     </toolkit:ContextMenu> 
    </toolkit:ContextMenuService.ContextMenu> 
</toolkit:HubTile> 

和CS文件後面的代碼進行檢查,如果它已經存在:

private void monday_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    CreateLiveTile(Monday, "path-to-xml", "monday_Square_0.png"); 
} 

private void CreateLiveTile(HubTile hubtile, string link, string id) 
{ 
    StandardTileData LiveTile = new StandardTileData 
    { 
     Title = hubtile.Title, 
     BackBackgroundImage = (hubtile.Source as BitmapImage).UriSource 
    }; 
    ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("id=" + id)); 
    { 
     if (Tile == null) 
     { 
      ShellTile.Create(new Uri("/Show.xaml?id=" + id + "&link=" + link, UriKind.Relative), LiveTile); 
     } 
     else 
     { 
      MessageBox.Show("The tile is already pinned"); 
     } 
    } 
} 

是否有它與一個水龍頭事件處理程序發生或者我需要爲所有100瓦100個自來水事件處理程序和每一個XML文件,100路和100個的事件處理程序固定到開始hubtiles動態方式並在xaml的每一個焦點上寫同樣的東西?

此外,我試過了,並認爲它是工作,使一個水龍頭事件處理程序,所有的hubtiles但我看到整個路徑hubtile的名字,不僅是瓷磚名稱:

private void Week_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    String a = (((Microsoft.Phone.Controls.HubTile)(sender)).Source as BitmapImage).UriSource.OriginalString; 
    String b = a.Replace(((Microsoft.Phone.Controls.HubTile)(sender)).Title + "_Square_0.png", "week.xml"); 
    String weekPath = a.Replace(((Microsoft.Phone.Controls.HubTile)(sender)).Title + "_Square_0.png", ""); 
    String weekName = ((Microsoft.Phone.Controls.HubTile)(sender)).Title;  
    NavigationService.Navigate(new Uri("/Show.xaml?parameter=" + b, UriKind.Relative)); 
} 

回答

7

每個控件具有Tag屬性。此屬性是object型,並已放在那裏。基本上,你可以把你需要的任何信息放在裏面。這是實現通用操作,如你試圖去做的寶貴的幫助。在事件處理程序

<toolkit:HubTile Name="Monday" Title="Monday" Source="Days\Weekdays\Monday.png" Margin="15" Tap="Tile_Tap" Tag="path-to-xml"> 

然後:

所以,你可以這樣做

private void Tile_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    var pathToXml = (string)((FrameworkElement)sender).Tag; 
    // Whatever 
} 
+0

感謝那些幫助了很多! –

相關問題