void Window_Loaded(object sender, RoutedEventArgs e) { this.storeData = StoreData.Initialize("JustADadSoftware.VillageDesigner.Data.CoCStoreData.xml"); if (null != this.storeData && null != this.storeData.Sections) { string screenShotUriBase = String.Format( "pack://application:,,,/{0};component/Images/{{0}}", typeof(MainWindow).Assembly.FullName); foreach (StoreSection storeSection in this.storeData.Sections) { BitmapImage storeSectionBitmapImage = new BitmapImage(new Uri(String.Format( screenShotUriBase, this.storeData.Screenshots[storeSection.StoreScreenIndex]))); ImageBrush storeSectionImageBrush = new ImageBrush(storeSectionBitmapImage); storeSectionImageBrush.Stretch = Stretch.UniformToFill; storeSectionImageBrush.Viewbox = storeSection.ScreenshotViewbox; storeSectionImageBrush.ViewboxUnits = BrushMappingMode.Absolute; ToolbarGroupButton storeSectionButton = new ToolbarGroupButton(); storeSectionButton.ImageBrush = storeSectionImageBrush; if (null != storeSection.Items) { foreach (StoreItem storeItem in storeSection.Items) { BitmapImage storeItemBitmapImage = new BitmapImage(new Uri(String.Format( screenShotUriBase, storeSection.Screenshots[storeItem.SectionScreenIndex]))); ImageBrush storeItemImageBrush = new ImageBrush(storeItemBitmapImage); storeItemImageBrush.Stretch = Stretch.UniformToFill; storeItemImageBrush.Viewbox = storeItem.ScreenshotViewbox; storeItemImageBrush.ViewboxUnits = BrushMappingMode.Absolute; ToolbarGroupItemButton itemButton = new ToolbarGroupItemButton(); itemButton.ItemID = storeItem.ItemName; itemButton.ImageBrush = storeItemImageBrush; itemButton.Tag = storeItem.BuildingID; itemButton.Click += new RoutedEventHandler(this.StoreItemButton_Click); storeSectionButton.Items.Add(itemButton); } } toolBoxPanel.Children.Add(storeSectionButton); } } }
void StoreItemButton_Click(object sender, RoutedEventArgs e) { ToolbarGroupItemButton storeItemButton = sender as ToolbarGroupItemButton; if (null != storeItemButton) { string buildingID = storeItemButton.Tag as string; if (!String.IsNullOrEmpty(buildingID)) { this.village.AddBuilding(buildingID); } } }
void Window_Loaded(object sender, RoutedEventArgs e) { this.storeData = StoreData.Initialize("JustADadSoftware.VillageDesigner.Data.CoCStoreData.xml"); if (null != this.storeData && null!=this.storeData.Sections) { string screenShotUriBase = String.Format( "pack://application:,,,/{0};component/Images/{{0}}", typeof(MainWindow).Assembly.FullName); foreach (StoreSection storeSection in this.storeData.Sections) { BitmapImage storeSectionBitmapImage = new BitmapImage(new Uri(String.Format( screenShotUriBase, this.storeData.Screenshots[storeSection.StoreScreenIndex]))); ImageBrush storeSectionImageBrush = new ImageBrush(storeSectionBitmapImage); storeSectionImageBrush.Stretch = Stretch.UniformToFill; storeSectionImageBrush.Viewbox = storeSection.ScreenshotViewbox; storeSectionImageBrush.ViewboxUnits = BrushMappingMode.Absolute; ToolbarGroupButton storeSectionButton = new ToolbarGroupButton(); storeSectionButton.ImageBrush = storeSectionImageBrush; if (null != storeSection.Items) { foreach (StoreItem storeItem in storeSection.Items) { BitmapImage storeItemBitmapImage = new BitmapImage(new Uri(String.Format( screenShotUriBase, storeSection.Screenshots[storeItem.SectionScreenIndex]))); ImageBrush storeItemImageBrush = new ImageBrush(storeItemBitmapImage); storeItemImageBrush.Stretch = Stretch.UniformToFill; storeItemImageBrush.Viewbox = storeItem.ScreenshotViewbox; storeItemImageBrush.ViewboxUnits = BrushMappingMode.Absolute; ToolbarGroupItemButton itemButton = new ToolbarGroupItemButton(); itemButton.ItemID = storeItem.ItemName; itemButton.ImageBrush = storeItemImageBrush; itemButton.Tag = storeItem.BuildingID; itemButton.Click += new RoutedEventHandler(this.StoreItemButton_Click); storeSectionButton.Items.Add(itemButton); } } toolBoxPanel.Children.Add(storeSectionButton); } } }