I have a comboBox that is styled to have rows of text blocks and check boxes to allow user to check a list of different things. What I am attempting to do is disable selection of a row in the the combobox.
My View Code:
<ComboBox ItemsSource="{Binding HeaderList}"
IsSelected="False"
HorizontalAlignment="Left"
Height="10"
x:Name="ComboBox">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}"/>
<TextBlock Text="{Binding HeaderName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Here is a picture of my Drop Down:
Here is a picture of what I don't want:
I want to disable the ability for the user to select a specific row, but keep the ability for them to select various check boxes in the drop down. Is there a way to style this?
I had the same issue, i solved it by using a ToggleButton in combination with a Popup (instead of using a ComboBox)
Note: Not tested
<ToggleButton x:Name="filterButton" />
<Popup x:Name="popup"
AllowsTransparency="True"
StaysOpen="False"
PlacementTarget="{Binding ElementName=filterButton}"
IsOpen="{Binding ElementName=filterButton,Path=IsChecked,Mode=TwoWay}">
<ItemsControl ItemsSource="{Binding HeaderList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}"/>
<TextBlock Text="{Binding HeaderName}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Popup>
You can try to set the selectedindex of your combobox to -1 in the selectionchanged event
private void myComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
myComboBox.SelectedIndex = -1;
}
Related
I'm trying to build a ListBox which allows the user to unselect the item.
This is my XAML code:
<ListBox Name="MyListBox"
ItemsSource="{Binding MoeglicheHauptspeisen}"
SelectionMode="Single">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="200"
Height="200"
Background="{StaticResource Braun}"
MouseDown="Speise_Gedrueckt">
<TextBlock Margin="0 50 0 0"
HorizontalAlignment="Center"
Text="{Binding SpeiseTyp}" />
<TextBlock HorizontalAlignment="Center" Text="{Binding Beschreibung}" />
<TextBlock HorizontalAlignment="Center" Text="{Binding Preis, StringFormat={}{0:C}}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And my code-behind:
private void Speise_Gedrueckt(object sender, MouseButtonEventArgs e)
{
MyListBox.UnselectAll();
}
I can unselect the item by clicking on it again, it does set SelectedIndex to -1 etc., but it doesn't clear the border that the selected item has in the ListBox itself.
I did google a lot but nothing I found did change that fact. I tried to set the border/background of the item which is selected via a style.setter, but it also didn't help.
Pay attention that Listbox item has 3 visual states - Selected, Not selected, and Focused. Even if you deselect Listbox item through code-behind, keyboard focus will still be there (assuming that you selected it by clicking on it). That's why some kind of visual indicator will be shown.
Not sure when do you want to clear the selected item so I added a button with the EventHandler:
<Button Width="100" Height="40" Click="Speise_Gedrueckt"></Button>
Now set the SelectedItem to null when the button is clicked:
private void Speise_Gedrueckt(object sender, RoutedEventArgs routedEventArgs)
{
MyListBox.SelectedItem = null;
}
I have a listbox, where I'm showing a list of titles. The user clicks the row to select the item which populates more textboxes.
However, the textboxes that I'm using in each row of the listbox are not clickable - the cursor changes to the text-selection cursor.
Is there something else that I should be using?
<ListBox ItemsSource="{DynamicResource products}" Width="319" x:Name="productsListBox" Height="300">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Title}" BorderThickness="0" IsReadOnly="True"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
readonly TextBox in template can be replaced with TextBlock
<DataTemplate>
<TextBlock Text="{Binding Title}" BorderThickness="0"/>
</DataTemplate>
I have 10 checkboxes in a listbox in windows phone.
My xaml file for checkbox into listbox is given below:
<ListBox x:Name="notificationSettingsListBox" Grid.Row="1" Margin="20,20,20,20" Background="#e79e38" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="#055cc3" Width="500" Height="200">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding channel_name}" Foreground="White" FontSize="31" TextAlignment="Left" TextWrapping="Wrap" />
<CheckBox Content="Enable Notification" Checked="pushNotiOnCheckBox_Checked" Unchecked="pushNotiOnCheckBox_Unchecked"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I access all checkboxes one by one like checkbox1.checked=true or checkbox2.checked=false and so on?
I see that you subscribe to both Checked and Unchecked events, one thing you could do is add this in the handlers
var box = (sender as CheckBox);
var value = box.IsChecked;
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.
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.