Click here to Skip to main content
15,888,113 members
Home / Discussions / WPF
   

WPF

 
QuestionHelp with a radio button Pin
abollmeyer18-May-12 16:44
abollmeyer18-May-12 16:44 
QuestionReferencing Resources Pin
Kevin Marois17-May-12 11:23
professionalKevin Marois17-May-12 11:23 
AnswerRe: Referencing Resources Pin
Madhan Mohan Reddy P21-May-12 18:45
professionalMadhan Mohan Reddy P21-May-12 18:45 
QuestionHow to get row number of a datagrid on mouse-move event Pin
Tilak Raheja16-May-12 20:20
Tilak Raheja16-May-12 20:20 
AnswerRe: How to get row number of a datagrid on mouse-move event Pin
Richard MacCutchan16-May-12 21:40
mveRichard MacCutchan16-May-12 21:40 
QuestionSilverlight chart Pin
Vishal Kumar Soni16-May-12 9:24
Vishal Kumar Soni16-May-12 9:24 
QuestionWPF Style With Multiple Content Elements Pin
Kevin Marois16-May-12 6:41
professionalKevin Marois16-May-12 6:41 
QuestionWPF Custom Combobox Control Issue - Please Help! Pin
Adam_Dev15-May-12 21:44
Adam_Dev15-May-12 21:44 
Hi

I am basically trying to create a control that consists of a combobox and some buttons (add, clear etc). I realise I could do it by creating a usercontrol with some codebehind, but I am trying to achieve this by defining a custom control class and a style for the control.

I have done the below based on other custom controls I have done, but the issue I am having is that the ItemsSource is always null and never gets set.

C#
[TemplatePart(Name = ComboBoxControl.INPUTCOMBOBOX_NAME, Type = typeof(ComboBox))]
    public class ComboBoxControl : Control
    {
        #region Constants
        const String CATEGORY_NAME = "Custom ComboBox Control";
        const String INPUTCOMBOBOX_NAME = "PART_InputComboBox";
        #endregion

        #region Properties
        ComboBox _inputComboBox;
        #endregion

        #region Dependency Properties
        public static readonly DependencyProperty DisplayMemberPathProperty =
            DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ComboBoxControl), new UIPropertyMetadata(String.Empty));

        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(ComboBoxControl), new UIPropertyMetadata());

        // Other properties omitted
        #endregion

        #region Dependency Public Properties
        public string DisplayMemberPath
        {
            get { return (string)GetValue(DisplayMemberPathProperty); }
            set { SetValue(DisplayMemberPathProperty, value); }
        }

        public object ItemsSource
        {
            get { return (System.Collections.IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }

        // Other properties omitted        
        #endregion

        #region Constructor
        public ComboBoxControl() { }

        static ComboBoxControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboBoxControl), new FrameworkPropertyMetadata(typeof(ComboBoxControl)));
        }
        #endregion

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _inputComboBox = (ComboBox)GetTemplateChild(INPUTCOMBOBOX_NAME);
        }
}


And the following style:

XML
<Style TargetType="{x:Type local:ComboBoxControl}">
        <Setter Property="Label" Value=""/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ComboBoxControl}">
                    <Border>
                        <DockPanel>

                            <!-- COMBO BOX  -->
                            <ComboBox x:Name="PART_InputComboBox" VerticalAlignment="Stretch" MinHeight="30"
                                      DisplayMemberPath="{TemplateBinding DisplayMemberPath}" 
                                      ItemsSource="{Binding Path=ItemsSource, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, 
                                AncestorType={x:Type local:ComboBoxControl}}, UpdateSourceTrigger=PropertyChanged}"/>
                        </DockPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


NOTE: I have omitted irrelevant code.

And trying to set it like this:

XML
<ctl:ComboBoxControl ItemsSource="{Binding Path=Users, Mode=TwoWay}"/>


But the value of the combobox itemsource is always null?!

Can anyone help please?

Thanks
AnswerRe: WPF Custom Combobox Control Issue - Please Help! Pin
Adam_Dev16-May-12 1:27
Adam_Dev16-May-12 1:27 
GeneralRe: WPF Custom Combobox Control Issue - Please Help! Pin
Pete O'Hanlon16-May-12 1:33
mvePete O'Hanlon16-May-12 1:33 
GeneralRe: WPF Custom Combobox Control Issue - Please Help! Pin
Adam_Dev20-May-12 21:38
Adam_Dev20-May-12 21:38 
Questionsingle line animation in wpf Pin
Member 859146215-May-12 19:18
Member 859146215-May-12 19:18 
QuestionShellExecute in WPF Pin
pix_programmer14-May-12 3:21
pix_programmer14-May-12 3:21 
AnswerRe: ShellExecute in WPF Pin
Pete O'Hanlon14-May-12 3:27
mvePete O'Hanlon14-May-12 3:27 
GeneralRe: ShellExecute in WPF Pin
pix_programmer14-May-12 3:35
pix_programmer14-May-12 3:35 
GeneralRe: ShellExecute in WPF Pin
Pete O'Hanlon14-May-12 4:08
mvePete O'Hanlon14-May-12 4:08 
GeneralRe: ShellExecute in WPF Pin
pix_programmer14-May-12 18:41
pix_programmer14-May-12 18:41 
GeneralRe: ShellExecute in WPF Pin
Richard MacCutchan14-May-12 21:45
mveRichard MacCutchan14-May-12 21:45 
GeneralRe: ShellExecute in WPF Pin
Pete O'Hanlon14-May-12 21:56
mvePete O'Hanlon14-May-12 21:56 
GeneralRe: ShellExecute in WPF Pin
Richard MacCutchan14-May-12 22:29
mveRichard MacCutchan14-May-12 22:29 
GeneralRe: ShellExecute in WPF Pin
Pete O'Hanlon14-May-12 21:55
mvePete O'Hanlon14-May-12 21:55 
QuestionSilverlight project publish Pin
yesu prakash14-May-12 1:35
yesu prakash14-May-12 1:35 
AnswerRe: Silverlight project publish Pin
ManojKumar1914-May-12 3:55
ManojKumar1914-May-12 3:55 
Questionemulator wp7 Pin
heba abu ghaleih22 13-May-12 23:34
heba abu ghaleih22 13-May-12 23:34 
AnswerRe: emulator wp7 Pin
Pete O'Hanlon14-May-12 0:13
mvePete O'Hanlon14-May-12 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.