Telerik RadComboBox Apply SelectionBoxTemplate OnLoad? - c#

Basically, we have created our own custom MultiSelect-ComboBox using Telerik's RadComboBox and the SelectionBoxTemplate to make the custom text appear when multiple items are selected.
<ucControls:MultiSelectComboBoxBase
... >
<ucControls:RadComboBox
x:Name="RadCombo"
Text=""
Height="22"
HorizontalContentAlignment="Left"
HorizontalAlignment="Stretch"
DropDownClosed="RadCombo_DropDownClosed"
IsTextSearchEnabled="False"
IsEnabled="{Binding IsEnabled}"
CanAutocompleteSelectItems="False"
CanKeyboardNavigationSelectItems="False"
LostFocus="RadCombo_LostFocus">
<ucControls:RadComboBox.SelectionBoxTemplate>
<DataTemplate>
<Grid Background="Aqua">
<TextBlock x:Name="ComboBoxDisplay" Text="{Binding Text, ElementName=RadCombo}" />
</Grid>
</DataTemplate>
</ucControls:RadComboBox.SelectionBoxTemplate>
<ucControls:RadComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox x:Name="chkBox"
Content="{Binding ItemValue}"
Tag="{Binding ItemID}"
Height="16" Margin="2"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Visibility="{Binding IsSelectAllItem, Converter={StaticResource booleanToVisibilityConverter}, ConverterParameter=NOT}"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
Checked="ChkBox_Checked" Unchecked="ChkBox_Unchecked"
IsEnabled="{Binding IsEnabled, Mode=TwoWay}"/>
<HyperlinkButton
VerticalAlignment="Center" Content="{Binding ItemValue}"
Visibility="{Binding IsSelectAllItem, Converter={StaticResource booleanToVisibilityConverter}}"
Style="{StaticResource HyperlinkButtonNoBorderStyle}" Margin="3,2,0,0"
Click="HyperlinkButton_Click"
IsEnabled="{Binding IsEnabled, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ucControls:RadComboBox.ItemTemplate>
</ucControls:RadComboBox>
It works great, but the only problem is that it appears that the SelectionBoxTemplate isn't actually applied when the radcombobox is loaded. It only applies when the box is clicked.When it loads it displays:
Then you click and it displays the dropdown:
Then you click away and it displays the correct text from the SelectionBoxTemplate:
Note I made the background color of the Textblock blue, just to show that it does not apply on the initial load.Ideally, when it loads it should automatically apply the SelectionBoxTemplate and display the correct information rather than having the click and then click away from the multiselectcombobox. Also, the TextBlock text is bound to the RadComboBox's text because in the code behind we set the RadComboBox's text. There is no issue with null values or the Text not being set before because I've looked in debugging mode and all the information is there, the selection box template is just not being applied until the box receives focus. Is there some sort of event that has to fire off before the template is applied, or is there someway I can force the template to be applied onload?

I had the same issue as you. I've managed to solve it by setting the SelectedIndex="0"
I've also read that the SelectionBoxTemplate only works when the RadComboBox is not editable: IsEditable="False"
<ucControls:RadComboBox
x:Name="RadCombo"
SelectedIndex="0"
IsEditable="False"
Height="22"
HorizontalContentAlignment="Left"
HorizontalAlignment="Stretch"
DropDownClosed="RadCombo_DropDownClosed"
IsEnabled="{Binding IsEnabled}"
LostFocus="RadCombo_LostFocus">
...
</ucControls:RadComboBox>

Related

WPF Clear combobox text value when checkbox is unchecked

I want to clear the combobox text value or set it to another string whenever the checkbox is uncheck. Is there any good way to bind them together in xaml ?
Thanks.
Maybe this helps. It is solved with bindings:
<Grid>
<ComboBox IsEditable="{Binding ElementName=Box, Path=IsChecked}" HorizontalAlignment="Left" Margin="211,167,0,0" VerticalAlignment="Top" Width="120">
<ComboBoxItem>Test</ComboBoxItem>
<ComboBoxItem>Test2</ComboBoxItem>
</ComboBox>
<CheckBox x:Name="Box" Content="Clear" HorizontalAlignment="Left" Margin="131,171,0,0" VerticalAlignment="Top"/>
</Grid>
If you want to change the text, it may be necessary to write a converter:
Text="{Binding ElementName=Box, Path=IsChecked, Mode=OneWay, Converter={StaticResource TextConverter}}"
Take a look at Microsoft Documentation about how to write a value converter.

Combobox with "Select All" CheckBox in SilverLight

I've ComboBox where I am binding list which will appear with CheckBox. Now I want to add "Select All" with CheckBox and when user select that, remaining all CheckBoxshould get selected. Following is my code where "Select All" appears before all items but I just want it once.
CODE:
<ComboBox x:Name="SynonymsCmbBx" ItemsSource="{Binding Synonyms}" Width="250" MaxDropDownHeight="100" Margin="0,0,375,0" ScrollViewer.VerticalScrollBarVisibility="Auto" Visibility="Collapsed">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="Select All" Height="16" Name="checkBox1" IsChecked="True" FontWeight="Bold" />
<CheckBox Content="{Binding Display}" Margin="10,0,0,0" IsChecked="{Binding Path=IsChecked, ElementName=checkBox1}" />
<!--<CheckBox Content="{Binding Display}" Margin="10,0,0,0" />-->
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ComboBox>
OUTPUT:
Subscribe the Select All's check/selected event and using the same process used to extract the checked values from the target checkboxes; reverse the processs and set the relevant checkboxes to true or false depending on the state.

AllowDrop in AutoCompleteBox in WPF does not work

I have a AutoCompleteBox control in my wpf application. I do not want to allow a value drop in it. I have bound AllowDrop=False but still I am able to drop values on it. Same is working very fine for my textbox. Can some one help.
here is my code:
<Control:AutoCompleteBox
Name="selectCountry"
Grid.Row="2"
Grid.Column="1"
Height="22"
MinWidth="80"
MaxWidth="80"
FilterMode="Contains"
HorizontalAlignment="Left"
IsEnabled="{Binding xxx}"
ItemsSource="{Binding xxx}"
SelectedItem="{Binding xxx, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
Text="{Binding xxx}"
ValueMemberPath="xx"
AllowDrop="False"
>

Listbox selection change not firing on click on child in list box item

I have a wpf user control which contains a Listbox which is binded to my View Model. Each Listbox item is consists of three textblock. I made the UI in a way that when user clicks on the Frist TextBlock(Title) function in my View Model will get called.
To uniquely Identify the ListBox item corresponding to which text block now got clicked. I added another property in my view model which is bindied to SelectionChanged Event in the Listbox. So whenever my TextBlock binded command get exectuted I will use my SelectionChanged Property to find which List Box Item and use its data context.
But the issue I am facing now is that when User clicks on the First textblock, selectionchanged event is not firing. When User clicks outside the First Textblock only Selection Changed event is getting fired. Which made my view model to process wrong list box items.
Following is the XAML snippet.
<ListBox ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedItem="{Binding SelectedNotificationItem}" ItemsSource="{Binding MyArray}" BorderThickness="0" Margin="0, 0, 0, 0" ItemContainerStyle="{StaticResource HoverBackgroundStyle}" Name="NotificationListBox" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Border BorderThickness="4,0,0,0" BorderBrush="{Binding ColorThing, Converter={StaticResource SeverityToColorConverter} }" Margin="0, 0, 0, 0">
<StackPanel Margin="8, 0" Orientation="Vertical">
<TextBlock Style="{StaticResource HoverUnderlineStyle}" FontWeight="Bold" TextTrimming="CharacterEllipsis" Name="Title" Text="{Binding Title}" TextWrapping="WrapWithOverflow" Margin="0,4,0,0" >
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ClickTitleCommand}"></MouseBinding>
</TextBlock.InputBindings>
</TextBlock>
<TextBlock FontWeight="Normal" Name="Desc" Text="{Binding Description}" TextWrapping="WrapWithOverflow">
</TextBlock>
<TextBlock FontWeight="Normal" Foreground="Gray" Name="Date" Text="{Binding CreationTime, StringFormat={}{0:ddd MM.dd.yyyy} }" Margin="0,4,0,4">
</TextBlock>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Could you try changing your XAML to SelectedItem="{Binding SelectedNotificationItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Change the ListBox into an ItemsControl and change the orientation to horizontal

Listbox inside the checkbox content - WPF

I have listbox inside the checkbox content. I want the checkbox to be checked whenever any click event happen in the listbox. But the problem it does not check, only clicking on the textblock does check. Any ideas how ?
<CheckBox Checked="orderItemChecked"
Unchecked="orderItemUnchecked"
Grid.Column="0" Grid.Row="0" IsChecked="{Binding Path=Completed}"
HorizontalContentAlignment="Stretch" >
<StackPanel>
<TextBlock Text="{Binding Path=sItemName}" ></TextBlock>
<ListBox Grid.Row="1" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Path=aSinglOptns}"
Margin="20,0,0,0"
ItemTemplate="{StaticResource SinglOptnTmpl}"
Style="{StaticResource SheetListStyle}"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"/>
</StackPanel>
</CheckBox>
Try turning the hit testing off from the ListBox:
<ListBox Grid.Row="1" IsHitTestVisible="false" ... />
You can subscribe the event PreviewMouseLeftButtonUp on the CHECKBOX and check it in code behind.

Categories

Resources