Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to create a editable Combobox (where I write what I want) with a color piker, this is, in the dropdown popup of the Combobox there is a list of all possible colors and when I choose one, the background of Combobox changes.

This is possible and how?

Best regards
Filipe Marques
Posted
Comments
Did you try anything? Where are you stuck?
Anisuzzaman Sumon 14-Dec-14 6:43am    
yes this is possible,Just try then ask for if needed
Filipe Marques 14-Dec-14 9:48am    
My problem is to prevent the selected item been show in the combobox. I spend all night long to figure out a solution and what I did was to create a user control with a Textbox and a Combobox (only the arrow button is visible). I do not know if is the best solution, but it works :D In the solution area, I show the code that I wrote. Best Regards, Filipe Marques

1 solution

Hi,

I figure out a solution. I do not know if it is the best one (I am almost 100% that is not) but ir works :D

Heres the code.

XAML

<usercontrol x:class="WpfCoWorker.CoWorkerSeparatorControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:osc="clr-namespace:WpfCoWorker"
        Name="coworkercontrol"
        mc:Ignorable="d" 
        d:DesignHeight="300" d:DesignWidth="300">
    <border name="mainborder" removed="{Binding ElementName=colorpicker, Path=SelectedBrush}">
        <grid>
            <grid.columndefinitions>
                <columndefinition width="*" />
                <columndefinition width="22" />
            </grid.columndefinitions>
            <textbox name="texbox">
                    Margin="0"
                    Padding="0"
                    Grid.Column="0"
                    Height="Auto"
                    Background="{Binding ElementName=colorpicker, Path=SelectedBrush}"
                    Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
            <osc:comboboxcolorpicker x:name="colorpicker" xmlns:osc="#unknown">
                    SelectedColor="White"
                    ColorChanged="colorpicker_ColorChanged"
                    HorizontalAlignment="Left"
                    Grid.Column="1"/>
        </grid>
    </border>
</usercontrol>


And de C# code

C#
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace WpfCoWorker
{
    public partial class CoWorkerSeparatorControl : UserControl
    {
        public String IText
        {
            get { return this.texbox.Text; }
        }
        public Color IColor
        {
            get { return this.colorpicker.SelectedColor; }
        }
        public String Text
        {
            get { return (String)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(String),
              typeof(CoWorkerSeparatorControl), new PropertyMetadata(""));

        public Color BckColor
        {
            get { return (Color)GetValue(BckColorProperty); }
            set { SetValue(BckColorProperty, value); }
        }

        public static readonly DependencyProperty BckColorProperty =
            DependencyProperty.Register("BckColor", typeof(Color),
              typeof(CoWorkerSeparatorControl), new PropertyMetadata(Colors.Transparent));

        public CoWorkerSeparatorControl()
        {
            InitializeComponent();
        }
    }
}


The osc:ComboBoxColorPicker is this control: http://www.codeproject.com/Articles/34376/Small-ColorPicker-for-WPF

I hope this helps someone.

Best regards
Filipe Marques
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900