ListView ReorderMode XAML - wpf

I'm stuck in a problem about WP8.1:
I have a ListView with ReorderMode = "Enabled"; so it is draggable and the user can reorder the list by dragging.
The problem is that when a listview is inside the ReorderMode state, its items become smaller, ther opacity diminishes, and the items are constantly moving around!! I'm looking for a way to avoid these secondary effects of the ReorderMode.
Everything would be much easier if the properties CanDragItems, CanReorder and AllowDrop worked in WP8.1, but it seems that they do not...
Does Anyone have any idea about how to prevent this behaviour from happening?
<ListView x:Name="SitesListContainer"
DataContext="{Binding RouteResultsVM.SelectedRoute.PlacesNotCurrentPosition, Mode=TwoWay}"
ItemsSource="{Binding}"
HorizontalContentAlignment="Stretch"
Background="{x:Null}"
SelectionChanged="SitesListContainer_SelectionChanged"
Grid.ColumnSpan="2">
Thank you in advance!

I have not tested this but try to get the default listview datetemplate and remove <ReorderThemeTransition /> that might work. here is the link ListView Default style

Related

Which tool is the best option for doing search in Datagrid in wpf?

I have created search option using combobox, for example
In combobox1 items are m1,m2,m3,m4,m5 based on that, if m1 item selected then
another combobox2 displays with items a,b,c,d and if a item is selected another
combobox3 dispalys, based on last combobox it searches on the datagrid.
I think it is long process, use of many combobox makes it lenghty. Is any
other way is their to implement this. plz help
<ComboBox Grid.Column="1"
Grid.Row="1"
x:Name="cmbType"
VerticalAlignment="Top"
IsEnabled="{Binding IsOther}"
ItemsSource="{Binding Source={StaticResource enumTypeOfType}}"
SelectedItem="{Binding SearchType,Mode=TwoWay}"
SelectedIndex="{Binding CmdResIndex,Mode=TwoWay}"
IsSynchronizedWithCurrentItem="True"
SelectionChanged="DataSource1"
Margin="0,0,1,0">
</ComboBox>
So if i get this right, you have a collection a, which goes to collection b,etc, and the second collection will change based on the selected item of the first? You have to remember, that since the data will change for each selection, hard coding the value is out of the question.
Knowing this, WPF provides you with a great mechanism for this. Using a stackpanel, with a list view will actually work.
<ItemsControl ItemsSource="{binding collections}" ItemTemplate="{binding TemplateForListViewItems}" ItemPanelTemplate="{binding itemPanelTemplate}"></ItemsControl>
Now, with the items control, one can simply set an ItemTemplate/DataTemplate, to set the styling of each control. Linking to the onclick event, or using interactions, you can simply do collections.Add to add your new list view with generated data for the selection, and done.

WPF Control remove focus and hover effect (FocusVisualStyle?!)

I am trying to remove the nasty looking effect on controls when hovering or focusing.
This seems not to work:
FocusVisualStyle="{x:Null}"
And this is what I got so far:
<ComboBox Grid.Row="2" HorizontalAlignment="Right" Background="Transparent" BorderBrush="#FFE87E00" FocusVisualStyle="{x:Null}"/>
Thanks in advance!
Look at the control template, you should be able to manipulate what occurs when visual states changes from there.

WPF contextmenu mouseover

I am wondering if there is a way to bind the current ContextMenu item to a property in WPF without first clicking on it.
For example:
<MenuItem MaxHeight="20"
HorizontalAlignment="left"
Header="Radio Group"
Name="cmRadio"
ItemsSource="{Binding RadioGroups, Mode=OneWay}" />
I'm hoping to be able to figure out what item the mouse is over before clicking.
Sorry for the lack of description ahead of time.
There are lots of "mouseover" events you could use, some totally in XAML.
Similar Problem
See farther down for the XAML answer.

How to get rid of a WPF Datagrid extra space (row?) at the bottom?

I have this datagrid, and sometimes it'll show that horrible gray space at the bottom, it doesn't even seem to have a pattern to show... Sometimes it's there, sometimes it's not.
I've tried CanUserAddRows to false and it does not fix it.
It's not an extra item in my collection either, I just checked that with the debugger.
I really need to remove that behavior, any ideas?
<DataGrid x:Name="NotesDataGrid" ItemsSource="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" Margin="0" Height="Auto" AutoGenerateColumns="False" CanUserAddRows="False" RowHeaderWidth="0"
GridLinesVisibility="All" HorizontalGridLinesBrush="#FFF7F7F7" VerticalGridLinesBrush="#FFF7F7F7" Padding="0"
AlternatingRowBackground="#FFFBFBFB" ColumnHeaderStyle="{DynamicResource dgColumnHeaderStyle}" CellStyle="{DynamicResource dgCellStyle}" RowStyle="{DynamicResource dgRowStyle}" LostFocus="NotesDataGrid_LostFocus">
I had the same problem and it was caused by the DataGrid's MaxHeight property not being set to a multiple of the row size, so the left over space was showing up at the bottom of the DataGrid. For example: if there are 5 rows that are 10 pixels in height and the MaxHeight property is set to 55 then there will be 5 pixels of space at the bottom.
Wrap your DataGrid in Grid and try DataGrid.VerticalAlignment="Top"
<Grid><DataGrid VerticalAlignment="Top" ... /></Grid>
Have you tried setting DataGrid.Background to white ?
I know it's long time since the question was asked. But anyway I had the same problem and I could fix it by setting a property of the Datagrid.
IsReadOnly="True"

WPF ListBox scrolls to top when I change status message or show wait screen

I'm developing an opensource application named Media Assistant. I used a ListBox to show the library. ItemsSource is bound to a list of LibraryItem. Here is the XALM.
<ListBox Name="Tree" DockPanel.Dock="Top"
ItemsSource="{Binding DataSource.OrderedLibraryItems}"
Background="{StaticResource LibraryBackground}"
Width="220" HorizontalAlignment="Left"
BorderThickness="0"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
ScrollViewer.IsDeferredScrollingEnabled="True"
ItemTemplate="{StaticResource ListLibraryItemTemplate}"
SelectionMode="Single"
MouseDoubleClick="HandleMouseDoubleClick"
/>
The problem is when I show any status message at the bottom of my window from a thread by using Dispatcher.
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,new ParameterizedThreadStart(action), state);
The ListBox scrolls to at the top. If I don't show any status message then it works just fine. The datacontext or list items or focus has not been changed. I could not found any reason why it's doing that. It happens when I display any wait screen which is a non modal window. I could not recreate it in a different project. Here is the source code of Media Assistant.
You can easily re-create it by un-commenting the return statement of method SetStatusMessage at BackgroundScanner class.
I found the reason behind this, so the solution.
I used a DockPanel to layout my UI. I put my status bar at the bottom, the ListBox on the Left and other items are on middle and top. There is a TextBlock in my StatusBar which has width and Height set to Auto. So, when I changed text of my StatusBar TextBlock it's width and height gets recalculated and It's parent's recalculates it's layout. Hence the ListBox gets invoked to Measures and Arrange. Even though it's size does not gets changed it resets it's scroll position to top. It happens only if I use ScrollViewer.CanContentScroll="True" at the ListBox. By default it is True. So, even though I did not set this value It was resetting the scroll position. If I disable it by using ScrollViewer.CanContentScroll="False" then it works fine.
<ListBox Name="Tree" DockPanel.Dock="Top"
ItemsSource="{Binding DataSource.OrderedLibraryItems}"
Background="{StaticResource LibraryBackground}"
Width="220" HorizontalAlignment="Left"
BorderThickness="0"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
ScrollViewer.IsDeferredScrollingEnabled="True"
ScrollViewer.CanContentScroll="False"
ItemTemplate="{StaticResource ListLibraryItemTemplate}"
SelectionMode="Single"
MouseDoubleClick="HandleMouseDoubleClick"
/>
But setting ScrollViewer.CanContentScroll="False" disables virtualization and I want to use virtualization to my ListBox so I set fixed Height and Width to the TextBlock. So, the DockPanel does not re-arrange it's children if I change the status message.
May be it's a bug at ScrollViewer. It should not change the scroll position if the size has not changed.
In reply to #user904627's answer, here is an enhanced version of his workaround. The issue with just fixing Width and Height is the ListBox keeps the same position even if the user resizes the Window. This is not acceptable.
This is why I created this tiny behavior which fixes Width and Height but listens to the parent element's SizeChanged event to let the ListBox resize itself when the container's size changes.
The code is here: VirtualizedListBoxFixBehavior
When the parent element is resized, I restore Width and Height to double.NaN (so the control can resize itself) and I queue the bit of code which fixes the size properties to actual values in the Dispatcher for later execution.
But this still is an ugly working workaround...
Try this:
listBox1.ScrollIntoView(listBox1.Items.GetItemAt(listBox1.Items.Count - 1));
Since the layout is being reset, it is expected that the list box to select the first item (0).
Can you try to set the selected item to the number of existing items in the list box:
Tree.SelectedIndex = Tree.Items.Count;
I did not test this solution on your code but I have used it in another project of mine where I had a similar problem.
Hope it helps.

Resources