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.
Related
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;
}
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 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
In my application using DataTemplate mechanism I insert into ListBox item another listbox. But is it possible that when selected one listboxitem in parent listbox, the focus may be on another parent listboxitem's child (see picture)
How to do: if one of child listbox in focus (one item from them selected), then parent listboxitem being selected to? Using binding or templating
<DataTemplate x:Key="NotesListBoxDataTemplate" DataType="Note">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<my:DatePicker Height="25" Name="datePicker1" Width="115" xmlns:my="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
SelectedDate="{Binding LastEdit,
Mode = TwoWay}" />
</StackPanel>
<TextBox Text="{Binding Path=Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<StackPanel Orientation="Horizontal">
<ListBox Name="ImagesListBox" SelectedIndex="{Binding Mode=OneWayToSource, Source={StaticResource progParameters}, Path=SelectedImage, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path=Images}" ItemTemplate="{StaticResource NotesListBoxImagesTemplate}" Style="{StaticResource HorizontalListBox}">
</ListBox>
<StackPanel Orientation="Vertical">
<Button Name="AddImageButon" Content="+" Click="AddImageButon_Click"></Button>
<Button Name="RemoveImageButon" Content="-" Click="RemoveImageButon_Click"></Button>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
On the parent ListBox set property IsSynchronizedWithCurrentItem to true, then in the inner ListBoxes set the SelectedItem property to "{Binding SelectedItem ElementName=lbParent}".
Consider using a Converter to help you get specific data that is not accessible thru xaml or if you need to do some caculations.
Hope this helps.