Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new <see cref="WallItem" /> with an image, if possible.
 /// </summary>
 /// <param name="wallName">The name of the wall.</param>
 /// <returns>A new <see cref="WallItem" />.</returns>
 internal static async Task <WallItem> Create([Required] string wallName) => await WallItem.wallItemsCache.GetOrAdd(wallName, async key =>
 {
     var wallItem = new WallItem()
     {
         Name = wallName
     };
     if (!string.IsNullOrWhiteSpace(wallName))
     {
         wallItem.Image = await App.GetWallFrame(wallName, "Uncolored", 0, 0, 0);
     }
     return(wallItem);
 });
        public static async Task <ColorToWall> Create(Color color, int numberOfPixels, EventHandler <WallSelectorChangedEventArgs> selectedColorChanged)
        {
            var colorToWall = new ColorToWall();

            colorToWall.cbWall.ItemsSource         = await ColorToWall.Walls;
            colorToWall.cbWallColor.ItemsSource    = ColorToWall.Colors;
            colorToWall.DataContext.Color          = colorToWall.DataContext.SelectedColor = color;
            colorToWall.DataContext.NumberOfPixels = numberOfPixels;
            colorToWall.SelectedColorChanged      += selectedColorChanged;
            colorToWall.ProcessColorChange         = true;
            if (color.A == 0)
            {
                colorToWall.DataContext.SelectedWall = await WallItem.Create("Glass Wall");

                colorToWall.Wall_SelectionChanged(colorToWall, null);
            }
            return(colorToWall);
        }
        async void FindClosestColor_Click(object sender, RoutedEventArgs e)
        {
            // Show the overlay on the main window and show the Find Closest Color dialog box.
            var mainWindow = Window.GetWindow(this) as MainWindow;

            mainWindow.ShowOverlay(false);
            var findClosestColor = await FindClosestColor.Create(this.DataContext.Color);

            findClosestColor.Owner = mainWindow;
            if (findClosestColor.ShowDialog() ?? false)
            {
                // This will only happen if the user clicked OK in the Find Closest Color dialog box.
                this.ProcessColorChange       = false;
                this.DataContext.SelectedWall = await WallItem.Create(findClosestColor.DataContext.SelectedColorItem.WallName);

                this.DataContext.SelectedWallColor = findClosestColor.DataContext.SelectedColorItem.ColorName;
                this.ProcessColorChange            = true;
                this.Wall_SelectionChanged(this, null);
            }
            mainWindow.HideOverlay();
        }