problem with Custom ComboBox not raising notification changes during SelectedItem change

Mesh Ka 345 Reputation points
2024-02-11T12:31:17.0866667+00:00

Hi, in my wpf C# .net 8 application i have a custom Control composed of a Label and ComboBox, the problem i am experiencing is that the Custom Control's ComboBox doesn't raise the SelectedItem change in the ViewModel, then i decided to test it with a normal wpf ComboBox and the notification was raised successfully, What can be the problem? Help fix the problem.

Here is the repos of this sample and Here is the Database i Used.
customcombobox

The two ComboBoxes you see use the same bindings and codes.

Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
Developer technologies | XAML
Developer technologies | XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. gekka 13,426 Reputation points MVP Volunteer Moderator
    2024-02-11T15:24:28.9133333+00:00

    TemplateBinding can receive only oneway from template parent.

    <Style TargetType="{x:Type local:FloatingLabelComboBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:FloatingLabelComboBox}">
                    <StackPanel FlowDirection="LeftToRight">
                        <Label Content="{TemplateBinding LabelText}"
                            Foreground="{TemplateBinding LabelForeground}"
                            FontSize="{TemplateBinding LabelFontSize}"
                            VerticalAlignment="Stretch"
                            Margin="-5 0 0 0" 
                    />
    
                        <ComboBox x:Name="comboBox"
                                ItemsSource="{TemplateBinding ComboBoxItemsSource}"
                                SelectedItem="{Binding ComboBoxSelectedItem,RelativeSource={RelativeSource  Mode=TemplatedParent},Mode=TwoWay}"
                                SelectedValuePath="{TemplateBinding ComboBoxSelectedValuePath}"
                                SelectedValue="{Binding ComboBoxSelectedValue,RelativeSource={RelativeSource  Mode=TemplatedParent},Mode=TwoWay}"
                                DisplayMemberPath="{TemplateBinding ComboBoxDisplayMemberPath}"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Center"
                                Width="Auto"
                                Height="Auto"
                                materialdesign:HintAssist.IsFloating="False"
                                materialdesign:ColorZoneAssist.Mode="Dark"
                                materialdesign:HintAssist.HintOpacity="0.10"
                                materialdesign:HintAssist.FontFamily="Century Gothic"
                                Foreground="{TemplateBinding ComboBoxForeground}">
    
                        </ComboBox>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.