WPF Color Picker Implementation

前端 未结 5 779
攒了一身酷
攒了一身酷 2020-12-13 09:35

I have to create a color picker in my WPF application. When I click on any color, the code of that color should come in a textbox. I googled a lot but found nothing matching

5条回答
  •  伪装坚强ぢ
    2020-12-13 10:26

    The easiest way is to use ColorDialog which were used in WinForms.

     System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DrawBallColorBtn.Background = new SolidColorBrush(Color.FromArgb(colorDialog.Color.A, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B));
                _drawBallColor = colorDialog.Color.Name.ToLower();
            }
    

    If you are targeting to a .NetCore 3.x add the fallowing to the .csproj file

    
        netcoreapp3.0
        true
        true 
    
    

提交回复
热议问题