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"
>
Related
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
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>
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.
I've two comboBoxes one above another. The problem appear if you open the form that contain this comboBoxes and avoid mouse over at lower comboBox, you just click on first comboBox and from drop down list choose item that is located right over the second comboBox. Once you click on an item the drop down list will close but your mouse will remain over the second comboBox. But this comboBox will not highlight and react on your clicks at all. Take a look at this picture please:
Both comboBoxes IsEditable = false; But if you move your mouse out of the 2nd comboBox and back over to it - everything will works fine. Help me please how to fix this.
UPD. XAML:
<ComboBox Background="{x:Null}" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,151,0,0" Name="comboBox2" VerticalAlignment="Top" Width="239" VerticalContentAlignment="Center" FontSize="14" IsReadOnly="False" Text="" SelectionChanged="comboBox2_SelectionChanged" TabIndex="6" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" AllowDrop="False" Cursor="Hand" IsTabStop="True" />
<ComboBox Background="{x:Null}" FontSize="14" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,190,0,0" Name="comboBox3" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="439" IsReadOnly="False" Text="" SelectionChanged="comboBox3_SelectionChanged" TabIndex="8" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" ClipToBounds="False" Cursor="Hand" IsHitTestVisible="True" SnapsToDevicePixels="True" UseLayoutRounding="True" />
Set Background property to White or Transparent instead of {x:Null}. Null background affects control hit-test behavior.
I have been looking on the internet for a solution of the problem I have.
Basically I want to select an item on a datagrid and that should update a few textboxes (not a problem) and a combobox (a nightmare)
Please see a code snippet for the combobox (& textboxes) below :
<TextBox Text="{Binding SelectedStudy.Description, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" />
<ComboBox ItemsSource="{Binding ModalityTypes, Mode=TwoWay}" DisplayMemberPath="ModalityTypeCode"
SelectedItem="{Binding ElementName=_studyDataGrid, Path=SelectedItem.Modality, Mode=TwoWay}" SelectedValuePath="Modality" />
<TextBox Text="{Binding SelectedStudy.Duration, Mode=TwoWay}" Width="200" HorizontalAlignment="Left"/>
My Datagrid :
<sdk:DataGrid x:Name="_studyDataGrid"
Grid.Row="1" Grid.ColumnSpan="2"
ItemsSource="{Binding Studies, Mode=OneWay}"
AutoGenerateColumns="False"
IsReadOnly="True"
SelectionMode="Single"
SelectedItem="{Binding SelectedStudy, Mode=TwoWay}"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
Margin=" 5,5,5,5"
>
The above code doesn't work, meaning whenever I click a row in the datagrid, the combobox doesn't get updated.
I also tried:
<ComboBox ItemsSource="{Binding ModalityTypes, Mode=TwoWay}" DisplayMemberPath="ModalityTypeCode"
SelectedValue="{Binding ElementName=_studyDataGrid, Path=SelectedItem.Modality, Mode=TwoWay}" SelectedValuePath="Modality" />
I'm lost, any ideas?
Regards,
Erik
If I understand correctly, you mean you want the selected value of the ComboBox to display dataGrid.
It is enough to ComboBox.SelectedValue =Cint( DataGrid.SelectedItems.Item(0).FieldName) to add.
this Code Add To DataGrid Selection Changed Event.
Good luck