Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Change color of blinking cursor XamComboEditor -> Textbox
posted

Hello there, I need some help.

I develop a .net core wpf (mvvm) application. I have a view with a XamComboEditor. I use a relatively dark background and therefore it is absolutely necessary to change the color of the blinking cursor of the underlying textbox of the XamComboEditor to white. I tried to get that style a whole day but nothing works. 

Can someone help me with this please?

Parents Reply
  • 2560
    Verified Answer
    Offline posted in reply to Phillippe Wilke

    Hi Phillippe,

    Sure, regarding your first question, styling the dropdown toggle button would not be as straightforward as it would involve overriding the default styles of the control. Actually, I found this forum thread, where the same question is discussed. You can read all details about the approach in Andrew Goldenbaum’s replies. There are also samples provided that demonstrate the suggestions.

    To address your second question, first the element to style you would be interested in is the ComboEditorItemControl. However, there would not be a Selected or similar property on this control, which would allow to target its selected state. Therefore, what needs to be implemented is rather each data item bound to the combo to have a member indicating that the item is selected, which could be used to bind a DataTrigger in the Style, for example: 

    <ig:XamComboEditor.ItemContainerStyle>
        <Style TargetType="ig:ComboEditorItemControl"
               BasedOn="{StaticResource customComboEditorItemControlStyle}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Item.Data.IsSelected, RelativeSource={RelativeSource Self}}"
                             Value="True">
                    <Setter Property="Foreground"
                            Value="Green" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ig:XamComboEditor.ItemContainerStyle>
     

    More about modifying the selected data items collection via a data model boolean property’s value can be read in the dedicated section in this documentation topic.

    For your convenience, I have modified the previous sample to demonstrate this approach. I have also added the necessary styles modifying the toggle button, as suggested in the above referenced forum thread. Please, check it out and of course, do modify the altered styles according to your specific application needs.

    If you are unsure, which element you have to modify, for example in the “ComboEditorDictionary.xaml” ResourceDictionary, I can suggest leveraging a tool like Snoop WPF to inspect the target elements.

    For instance, some of the modified colors in the sample are for the “selectedRectangle” (line 434), “FocusVisualElement” (line 441) and “mouseOverRectangle” (line 428) in the dictionary.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer

    5381.XCEInput-CaretBrushModified.zip

Children