Hello,
I'm running into a problem involving focus not being lost on an editable RadComboBox (in a property grid) when I click on a RadRibbonButton (in a RadRibbonGroup). If I type some text into the combo box text area, it is not stored to the dependency property that it is bound to until the control loses focus.
This is required because the Value property is coerced to a valid string before being accepted, and without UpdateSourceTrigger=LostFocus the text box fails to take on the coerced value, something broken in the binding there.
If UpdateSourceTrigger was set to PropertyChanged, this setter would be called every time the user types any characters. If they type an invalid character the coerce function leaves the property unchanged but the text box displays the incorrect string, even though Value is different.
If the user starts typing something into the combo box and then clicks the button (which does a save or export), the Value is not set because the combo box does not lose focus.
These two controls are in different assemblies. I tried clearing focus for the scope in the button command code-behind but at that time Keyboard.FocusedElement is the button. I can't find any way to force all focus scopes to clear their FocusedElement fields either. I tried playing with the button's IsTabStop property. I tried hooking up to a focus changed event on the button (can't find one that gives me the previously focused element, and it probably wouldn't be what I want thanks to focus scopes).
I might be able to cache off the element every time something changes focus in the property grid and clear its focus scope on button clicks, but this doesn't seem very scaleable.
So I need to fix one of two problems. Either figure out how to clear focus on the combo box when the button is clicked but before the command is executed, or figure out how to fix the binding issue of the text in the combo box. Do you have any advice on either fronts?
TIA, Jay
I'm running into a problem involving focus not being lost on an editable RadComboBox (in a property grid) when I click on a RadRibbonButton (in a RadRibbonGroup). If I type some text into the combo box text area, it is not stored to the dependency property that it is bound to until the control loses focus.
<
telerik:RadComboBox
IsMouseWheelEnabled
=
"False"
ItemContainerStyle
=
"{StaticResource ComboBoxItemStyle}"
IsEditable
=
"True"
Text
=
"{Binding Value, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
>
<
telerik:RadComboBox.ItemsSource
>
<
Binding
Converter
=
"{StaticResource AssetToListConverter}"
>
<
Binding.Path
>Value</
Binding.Path
>
</
Binding
>
</
telerik:RadComboBox.ItemsSource
>
</
telerik:RadComboBox
>
This is required because the Value property is coerced to a valid string before being accepted, and without UpdateSourceTrigger=LostFocus the text box fails to take on the coerced value, something broken in the binding there.
public Object Value
{
get
{
return _property.GetValue(_asset, null); //using reflection
}
set
{
//SetValue ends up calling a coerce function which leaves the property untouched if value is invalid
_property.SetValue(_asset, value, null);
RaisePropertyChanged(() => Value);
}
}
If UpdateSourceTrigger was set to PropertyChanged, this setter would be called every time the user types any characters. If they type an invalid character the coerce function leaves the property unchanged but the text box displays the incorrect string, even though Value is different.
If the user starts typing something into the combo box and then clicks the button (which does a save or export), the Value is not set because the combo box does not lose focus.
<
telerik:RadRibbonGroup
x:Name
=
"root"
Header
=
"Destructible"
DialogLauncherVisibility
=
"Collapsed"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadRibbonButton
Grid.Row
=
"0"
Grid.Column
=
"0"
Text
=
"New"
IsAutoSize
=
"True"
Command
=
"{Binding NewCommand}"
/>
<
telerik:RadRibbonButton
Grid.Row
=
"1"
Grid.Column
=
"0"
Text
=
"Save"
IsAutoSize
=
"True"
Command
=
"{Binding SaveCommand}"
/>
<
telerik:RadRibbonButton
Grid.Row
=
"2"
Grid.Column
=
"0"
Text
=
"Export"
IsAutoSize
=
"True"
Command
=
"{Binding ExportCommand}"
/>
</
Grid
>
</
telerik:RadRibbonGroup
>
These two controls are in different assemblies. I tried clearing focus for the scope in the button command code-behind but at that time Keyboard.FocusedElement is the button. I can't find any way to force all focus scopes to clear their FocusedElement fields either. I tried playing with the button's IsTabStop property. I tried hooking up to a focus changed event on the button (can't find one that gives me the previously focused element, and it probably wouldn't be what I want thanks to focus scopes).
I might be able to cache off the element every time something changes focus in the property grid and clear its focus scope on button clicks, but this doesn't seem very scaleable.
So I need to fix one of two problems. Either figure out how to clear focus on the combo box when the button is clicked but before the command is executed, or figure out how to fix the binding issue of the text in the combo box. Do you have any advice on either fronts?
TIA, Jay