I have a table, where in the first column I want to show a checkbox (currently of type CheckEdit) which enables the user to select/deselect items, and their name. Currently I have the following:
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<DockPanel VerticalAlignment="Center" LastChildFill="True">
<dxe:CheckEdit IsChecked="{Binding Path=RowData.DataContext.IsSelected}"
DockPanel.Dock="Left"
Margin="0,0,5,0"/>
<Border BorderBrush="{x:Null}"
VerticalAlignment="Center">
<TextBox Text="{Binding Path=RowData.DataContext.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0" />
</Border>
</DockPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
I have enabled multi-selection on the table, and I want it simply that if the user clicks one of the checkboxes, all of the selected checkboxes get the new value, and all of the rows stay selected.
What happenes now is that the CheckEdit-element that was clicked, gets a new value just as it should, all others remain unchanged, and the selection changes to only that specific row where the user clicked.
I have played around with GotFocus, PreviewMouseDown and MouseDown. None really worked as I want.
How can I get this behaviour?
Related
If I put the Column where the toolbar is hosted to be very big (800) then all the text is visible:
but if I put a smaller column this happens:
But I cannot understand why:
<DataTemplate x:Key="IconFilterButton">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource LargeIconStyle}"
Text="{Binding}" />
<TextBlock
Margin="6,0,0,0"
VerticalAlignment="Center"
DataContext="{Binding}"
Style="{StaticResource BodyTextStyle}"
Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Tag}" />
</StackPanel>
</DataTemplate>
and here the definition
<ToggleButton
x:Name="DFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1d"
/>
<ToggleButton
x:Name="WFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1w"
/>
Even worst if I click on the button once they are out:
and then the text is visible but is wrong as the TextBlock is not considered in the object size:
The WPF ToolBar control uses a custom panel for the overflow Popup. In many styles, the ToolBarOverFlowPanel has a property WrapWidth set to a static value like 200. This determines how many items can be displayed before it wraps to another row in the popup.
I've created custom styling for this control and have found that the ToolBarOverFlowPanel used internally is buggy. That's probably the source of your problem.
You can re-template the ToolBar and wire-up a different value for WrapWidth to try to fix the issue, but my guess is that you'll still run into layout problems.
Otherwise, you might consider making your own replacement control.
I have listbox which will show the list of text and its status. How shall i show the text in the left side and Status control on the right most side?
This is how i was trying.
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Left" Text="{Binding Path=Name}" Style="{StaticResource TextBlockTitle}"/>
<ContentControl DockPanel.Dock="Right" HorizontalAlignment="Right" Content="{Binding Status}" ContentTemplate="{StaticResource StatusTemplate}" />
</DockPanel>
</DataTemplate>
This code is showing the status control just after the text.
Would use a Grid with two columns:
* sized
Auto sized (or set a SharedSizeGroup if you want synchronization between items)
The first column will take up all space left. For size sharing you will also need to set Grid.IsSharedSizeScope on e.g. the ListBox element.
The items also need to be stretched.
I have a simple data template for the new Windows Phone 8 LongListSelector as follows:
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,-6,0,-10">
<CheckBox x:Name="ToDoCheckBox" Margin="0" IsChecked="{Binding ItemIsComplete}" Checked="ToDoCheckBox_Checked"/>
<TextBlock Text="{Binding ItemName}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeExtraLarge}"/>
</StackPanel>
</DataTemplate>
There are suppsed to be a few more items in the template, that's why CheckBox's content property hasn't been used.
Now, I have page navigation implemented on SelectionChanged event. Problem is that, SelectionChanged even is fired even when the CheckBox is clicked. Earlier questions seem to discuss exactly opposite issue. I do not want SelectionChanged to be fired. Or, at least I don't want page to navigate on CheckBox events. I just want to have checkbox checked or unchecked event. How do I achieve that?
Selection is a bad way to trigger navigation. Without digging into that, you can avoid this by triggering the navigation when the other item in the template is tapped.
e.g.
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,-6,0,-10">
<CheckBox x:Name="ToDoCheckBox" Margin="0" IsChecked="{Binding ItemIsComplete}" Checked="ToDoCheckBox_Checked"/>
<TextBlock Text="{Binding ItemName}"
TextWrapping="NoWrap"
Style="{StaticResource PhoneTextExtraLargeStyle}"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
Tap="TriggerNavigationToThisItem"/>
</StackPanel>
</DataTemplate>
The above assumes you have an event called TriggerNavigationToThisItem which will trigger the navigation. You could also add a command on the Item and bind to that to trigger the navigation.
If you have a more complex template you could encapsulate them in a container (like a Grid) and then have that trigger the navigation.
You can check the original source of en every selection changed event. If it is the checkbox - simply skip execution.
Also. Don't use native "LongListSelector.Selected" property and selection event at all. It has completely no scalability (for example for multiselection). Implement it with your own Tap event handling.
I am customizing a templated multi-selection-enabled ListBox and can't easily implement the following feature - if there is only one item selected which is also current (focused), when user navigates up or down the list the selection should follow current item. I tried to subscribe to GotFocus event of the DataTemplate's StackPanel, but apparently I don't receive those events (even though MouseEnter/MouseLeave work).
I guess I could do it by modifying a somewhat similar behavior, but isn't there an easier way? This looks like a pretty basic behavior to me...
<ListBox>
<ListBox Name="lbItems" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
MouseEnter="UIElement_OnMouseEnter"
MouseLeave="UIElement_OnMouseLeave"
GotFocus="UIElement_OnGotFocus">
<Rectangle Width="15" Height="15" Fill="{Binding Path=Brush}" />
<TextBlock Text="{Binding Path=Category}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I've spent a few minutes searching on Google and have not found anything related to this issue I'm having:
Today I upgraded to the Silverlight 3 SDK and converted a project that I'm working on. I then noticed a bug in my program with a Listbox that has a Checkbox as its DataTemplate.
When one or more items is checked, and I scroll up and down, it seems that a few of the Checkboxes at the extremes get checked off and on randomly. This does not trigger the Checked/Unchecked event, however.
Has anyone seen this behavior? I'm not doing anything out of the ordinary, simply scrolling up and down once at least one checkbox has been checked, and a couple of others that I have not touched seem to get checked on and off repeatedly. This was definitely not happening with the Silverlight 2 SDK.
Here's the XAML definition for my Listbox:
<ListBox x:Name="cBoxSalesmen" Width="135" Height="200"
HorizontalAlignment="Left" VerticalAlignment="Top">
<ListBox.Template>
<ControlTemplate>
<Border Style="{StaticResource BorderStyleThin}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Salesmen" />
<ScrollViewer Height="176" VerticalScrollBarVisibility="Visible" >
<ItemsPresenter />
</ScrollViewer>
</StackPanel>
</Border>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Margin="0" Content="{Binding}" FontSize="10" HorizontalAlignment="Left"
Checked="SalesmenCheckbox_Checked" Unchecked="SalesmenCheckbox_Unchecked"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The default ItemsPanel of the ListBox is the VirtualizingStackPanel. You can change it to use the StackPanel, this way you problem is solved.
Use this code:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
<ListBox.ItemsPanel>
I suspect your problem is a result of ListBox (in SL3) now using an ItemCollectionGenerator. The concept behind this is that not all the objects found in the source data collection need to have had their corresponding instance of the DataTemplate created and added to the Visual Tree. As you scroll toward the bottom items that may soon be needed are created. Additionally items that have already be created but are now scrolled quite same way out of view can be removed. If the user scrolls up they are re-created.
If this is the case then the IsChecked state of any checkbox in this list will be lost at some point for large lists. To solve this you would need include a property in the data type to which you can bind IsChecked. Hence as ListBox re-creates items it correctly assigns the IsChecked value.