Sometimes when I view a certain window with a ComboBox, the box appears as follows:
Why does it appear with this red outline sometimes? Is there any way for me to get information on what is going on in the background when this occurs?
The ComboBox is defined as:
<ComboBox Grid.Column="1" Grid.Row="1" Name="cbConnectMethod"
ItemsSource="{Binding ConnectMethodList}"
SelectedItem="{Binding SelectedConnectionMethod}"
DisplayMemberPath="Description" VerticalAlignment="Center"
Width="Auto" HorizontalAlignment="Left" />
And the properties for ItemSource
and SelectedItem
are defined as:
public class ConnectMethod
{
public Connection Method { get; set; }
public string Description { get; set; }
}
public List<ConnectMethod> ConnectMethodList { get; set; }
public ConnectMethod SelectedConnectionMethod
{
get
{
return ConnectMethodList.FirstOrDefault(xx => xx.Method == _dataContainer.ConnectionData.Connection);
}
set
{
if (_dataContainer.ConnectionData.Connection != value.Method)
{
_dataContainer.ConnectionData.Connection = value.Method;
updateConnectDetailPage();
}
}
}
Connection
is just an enum, defined as:
public enum Connection
{
USB = 4,
Serial = 1,
Modem = 3,
SomethingElse = 2,
IP = 5,
AnotherThing = 6,
}
The red border around your ComboBox
looks like the validation error that is caused by a miss-matched type in a Binding
. You can find out what the error is if you data bind the value of the first item from the Validation.Errors
collection to a ToolTip
. Try something like this:
<ComboBox Grid.Column="1" Grid.Row="1" Name="cbConnectMethod"
ItemsSource="{Binding ConnectMethodList}"
SelectedItem="{Binding SelectedConnectionMethod}"
DisplayMemberPath="Description" VerticalAlignment="Center"
Width="Auto" HorizontalAlignment="Left"
ToolTip="{Binding (Validation.Errors)[0].ErrorContent,
RelativeSource={RelativeSource Self}}" />
Once you can see what the error is, then you will be able to address it and fix your problem, which will in turn remove the red border from your ComboBox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With