WPF ComboBox BorderBrush won't change


I'm constructing a sign-in screen for a database connection. Right now, I'm doing data validation on the form, and would like to set a red border on fields that fail validation. This works perfectly on TextBoxes and PasswordBoxes, but I can't get it to work on the ComboBox.

I've looked around different threads and found people who got it working the same way I've tried to, but for whatever reason, it's not working on my setup.

How I'm setting the borders now:
(Commented out is another method I was trying to see if I could get any results.)

private void activateValidationErrorHighlight(Control uiElelment)
    uiElelment.SetValue(Border.BorderBrushProperty, new SolidColorBrush(Color.FromArgb(0xFF, 0xD0, 0x50, 0x50)));

    //uiElelment.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD0, 0x50, 0x50));

I've also tried editing it directly like this myComboBox.BorderBrush = Brushes.Red;

XAML for a ComboBox:

<ComboBox Name="cb_DevelopmentServer" Text="Server"
                Grid.Column="0" Grid.Row="4" 
                Margin="5" Padding="5" 
            <CollectionContainer Collection="{Binding Path=ComboTest}" />

Taking a look at the LiveVisualTree during run-time, I found that there is a BorderBrush property being set in the element itself, but there is a Border element within the ComboBox that is not being set.

If at all possible, I'd like to do this without having to climb around the VisualTreeHelper.

I'm rather new to WPF and XAML, so I wouldn't be overly surprised to find that there is an issue somewhere else in the app that is causing this. If you think that's possible, could you advise me as to where I might look?


Unfortunately nobody got back to me on this, and I've been unable to solve the problem.

Here is what I did for anyone with the same problem:

As a workaround, I'm taking the borders off of all elements right in the Xaml (setting thicknesses to 0), and adding a tag with a name I know around anything I need to highlight for validation.

All I had to do was pass the border element into the function activateValidationErrorHighlight defined in the original post.

The type of e1 is Event the type of e2 is *Event. The initialization is actually the same (using composite literal syntax, also not sure if that jargon is Go or C# or both?) but with e2 you using the 'address of operator' & so it returns a pointer to that object rather than the instance itself.

Subtract the julian day integer of the earlier date from the julian integer of the later date. The following tells you exactly how to do that.


Otherwise, http://pdc.ro.nu/jd-code.html already has a C version

long gregorian_calendar_to_jd(int y, int m, int d)
    if(m<3) { y--; m+=12; }
    return (y*365) +(y/4) -(y/100) +(y/400) -1200820

This video can help you solving your question :)
By: admin