I am migrating some win forms panels to WPF.
In WinForms, you can tab into to the combo box using the keyboard, select an item by typing the first character and then hit tab again and the combo to lose focus.
In WPF the second tab will move the focus rectangle down the list, instead of moving onto the next control.
Is there a way to get the old behavior? Or has anyone implemented an ItemTemplate that achieves this behvaiour?
thanks
There is a ComboBoxItem which has an IsTabStop property.
So I just applied the appropriate style:
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsTabStop" Value="False"/>
</Style>
Related
I am facing the following issue. When i am removing the first element from a list box which has keyboard focus(by refreshing the item source) the keyboard focus is moving to the parent window. I want to retain the keyboard focus on the fist listbox item. So i came up with the following code
<Grid.Resources>
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding FirstRowDeleted}" Value="True">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=MyListBox}" />
</DataTrigger>
</Style.Triggers>
</Style>
Using this code i am able to move the focus to the list box itself. How can i move the focus to the first listbox item? MyListBox[0] does not seem to work. Any suggestions?
Thanking you
Kaddy
I found answer here: How do you programmatically set focus to the SelectedItem in a WPF ListBox that already has focus?
var listBoxItem = (ListBoxItem) MainListBox
.ItemContainerGenerator
.ContainerFromItem(MainListBox.SelectedItem);
listBoxItem.Focus();
Thanks for #Jeff for the answer.
This code applies the focus function to the first input text when the page loads. try it out
$(document).ready(function () {
$("#input:text:visible:first").focus();
});
I have a ListBox using a Panel as its ItemsPanel
What I would like to do is load the bytes for an image into the bound property in the view model for each ListBoxItem that is currently on screen, and unload the bytes when they are scrolled off screen.
I have tried Panel.OnVisualChildrenChanged. This tells me when items are added or removed to the panel, but doesn't seem to help my specific case.
I have tried
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="RequestBringIntoView" Handler="EventSetter_OnHandler" />
</Style>
That event never seems to fire. edit: fires when item is selected
I have also gotten a reference to the ListBox ScrollViewer to look at the VerticalOffset and Viewport.Height/Width but I don't see how that information helps me.
I have an autoCompleteBox in my wpf window and I set ValidatesOnDataErrors binding property to True for selectedItem property of autoCompleteBox control.
When I show my wpf window by clicking on a ribbon Button, Validation Area of autocompletbox does not render correctly.
like the picture below:
but when I show window by clicking on a standard Wpf button it work correctly
like the picture below:
for more info I create and attached a sample source code:
sample of my problem
can anyone help me ?
Thanks.
You're seeing both the custom error UI defined in the AutoCompleteBox's control template and the standard error template in the adorner. You should disable the latter:
<Style TargetType="{x:Type sysctrls:AutoCompleteBox}">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
</Style>
I am working on winRT C# app. I have Textbox with custom font-family. Due to custom font-family my text in Textbox is aligned to top of Textbox. I tried to set VerticalContentAlignment to "center" but it still not working.
I'm not so sure it's because of your font, and more likely expected behavior of the TextBox. I would take a look at the control template for your TextBox and check your Setter's and ContentPresenter to see if there isn't a property set to make it that way. Otherwise I think you can touch it via something like;
<TextBox>
<TextBox.Resources>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</TextBox.Resources>
</TextBox>
I have a combo box inside a list view. And different items (rows) in the list view need to display (based on some condition) one among 3 sets of combo box items in the respective combo box which is . Right now I am achieving this by using 3 data templates bound to 3 different properties of List<string>. I am hooking up the appropriate data templates during the DropDownOpened event of the combo boxes.
The problem that I am facing is that I am having to click the combo box twice each time to have it dropped down. I did a Debug.WriteLine() to see if my first click does the job of selecting a data template, I found that it indeed does. But just that it does not drop down at the first click itself.
I guess this is because I am changing the data template after the combo box has dropped down its popup and hence it refreshes again whose results are furnished only after I perform the second click.
My question is whether there is any other way of accomplishing what I am trying or do I have to make any changes in my existing DropDownOpened event handler.
Please suggest.
EDIT : I'm using WPF
Thanks
Would it be an option to use styles to set the items? e.g.
<ComboBox>
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding SomeConditionalProperty}"
Value="SomeConditionalValue">
<Setter Property="ItemsSource" Value="{BindingToFindRightItems}"/>
</DataTrigger>
<DataTrigger Binding="{Binding SomeConditionalProperty}"
Value="AnotherValue">
<Setter Property="ItemsSource" Value="{BindingToFindRightItemsForAnotherValue}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>