Telerik DragDrop Does not work - c#

I've been developing a software and i want to use telerik Listbox drag&drag.
the problem is when i drop an item from one listbox to another it does not work at all.
It seems that the drop event does not fire.
I set allowdrop= true
I added dragvisualprovider
I set allowreorder = true
I also tried to write code when dragLeave and PreDrop Events Fire and add that item into the new Listbox. but it works sometimes correct by chance!!!
I don't use MVVM Model
based on what telerik site says, I don't use static items collection. I create new items in my page load and add it to first Listbox.

You have to use <telerik:ListBoxDragDropBehavior AllowReorder="True" /> like this:
<telerik:RadListBox ScrollViewer.VerticalScrollBarVisibility="Visible" SelectedItem="{Binding DataContext.SelectedItem, ElementName=editor,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemContainerStyle="{StaticResource DraggableListBoxItem}" DisplayMemberPath="DisplayName" ItemsSource="{Binding LeaveActions,Mode=TwoWay}" Grid.Row="3" AllowDrop="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<telerik:RadListBox.DragDropBehavior>
<telerik:ListBoxDragDropBehavior AllowReorder="True" />
</telerik:RadListBox.DragDropBehavior>
</telerik:RadListBox>
Than every thing should work well. If you want to get into the drag/drop events, just use the telerik DragDropmanager.

Related

How to Change border of selecteditem

I have one main window.xaml, inside which i have referred Viewmodel and another xaml page called Template.xaml.
Mainwindow.xaml will be some thing like below:
<Window ...>
<Window.Resorce ../>
<Window.DataContext>
<local:Viemodel/>
</Window.DataContext>
<Grid...
<local:Template/>
</Grid>
</Window>
And this is my Tempaltes.Xaml:
<ItemsControl HorizontalAlignment="Left" ItemsSource="{Binding Path=ControlsList}" KeyboardNavigation.IsTabStop="False">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="950"
Margin="28"
KeyboardNavigation.IsTabStop="False"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Name="Mybutton" Height="200" Background="Red" Command="{Binding Path=SupportButton}">
.....
In tha above block i have used binding in 3 places.
1. Item Controls
2. Button
3. Image
And here the command binding was not working for "MyButton". What may the reason behind this?
I need to change the background of button once the particular item is chosen. How to achieve that?
Under the button properties there is additionally a tab for actions or action methods. You'll want to find the one that is a button clicked event.
Once you have created an event handler from that action you will have the ability to change the background or foreground of the button.
Not 10% sure what you're trying to achieve here, but perhaps a ListBox would work better for you?
It'll automatically change the background of the item while it's selected and remove the background when another item is selected. If you want to perform an action when the selected item changes you could bind to the SelectedItem property.
Just a thought...
It's difficult to tell from the question but it sounds like using a ToggleButton may be appropriate in your case. If you go that route, you could simply bind the IsChecked property to your View Model, and your property setter could perform any command-like logic.
And of course you could style the ToggleButton any way you like, so the IsChecked state could look relatively different from the Normal state.

ItemClick event on part of GridView

I have a collection of objects that I want to bind to my Xaml (using a GridView at the moment). I don't know if a GridView is the best tool for what I want to achieve.
This is roughly my current DataTemplate:
I need a clicked/tapped trigger on Grid1. But when I use this template with a GridView, the ItemClick event will get triggered on the complete template - which is correct of course. How can I set an click event on Grid1? Can I add this event in my DataTemplate declaration?
That's basically the xaml for my GridView:
<GridView x:Name="RoomsGridView"
VerticalAlignment="Top"
ItemsSource="{Binding Rooms}"
ItemTemplate="{StaticResource RoomTemplate}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="RoomsGridView_ItemClick" Padding="0">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
Edit: I've found this sample but this seems only to work with Buttons!?
In the code you posted above you've told to GridView to capture item clicks via IsItemClickEnabled="True". You cannot have that option enabled if you want to be able to click on elements inside the DataTemplate.
I would suggest that you disable IsItemClickEnabled and instead add a click handler to your Grid1. Even better would be to substitute your Grid1 with a button that has custom styling. This would further allow you to bind the button to a command that you can control from your view model.

Select an item from checkedlistbox using wpf,mvvm

I am new to MVVM, I have a checkedlistbox in a view with the list of titles(have bound the exposed property in ViewModel to this checkedlistbox control)...
Here is my XAML code that populates the ListCheckBox -
<ListBox x:Name="lstCode" ItemsSource="{Binding Code,Mode=TwoWay}" Grid.Row="1" Style="{StaticResource ListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="chkBox" IsChecked="{Binding IsChecked,Mode=TwoWay}" Content="{Binding Code_Name}" Margin="0" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This control shows the correct list of items with checkboxes for each item in the listbox...
What should be the code in viewmodel to make it work in two way - while getting the codes from database, it should automatically selected the code from the listcheckedbox and when the user selects one or more codes, the viewmodel should be able to know the items selected...
In general, for TwoWay binding, you will need to implement the INotifyPropertyChanged interface on the ViewModel you want to bind to.
In this case, your ViewModel will have to provide a property that returns a collection that your view can bind to, e.g. an ObservableCollection.
This ObservableCollection already allows you to add, update, and delete items in that list in a way that automatically communicates the changes between View and ViewModel.
For the rest I suggest to start digging into MVVM depths. To fully take advantage of WPF's capabilities, you will need to understand the basics for yourself. A great starting point is this SO thread: MVVM: Tutorial from start to finish?

AutoCompleteBox in silverlight toolkit for windows phone wrong display

I'm having a problem with the autocompletebox from the toolkit for windows phone. I bind it to some data, then when i press it and start typing, it discovers some items but they are displayed wrong (the list is shown separated from the box, and also if i click on any item, nothing happens. If i click where the item would be supposed to be (for example, right on the top of the box), then it gets selected. It looks like a rendering problem (bug?)) but perhaps i'm doing something wrong. Here's the code for the box :
<DataTemplate x:Key="DataTemplate1">
<ContentControl Content="{Binding Name}" Margin="8,7"/>
</DataTemplate>
<toolkit:AutoCompleteBox ItemsSource="{Binding}" x:Name="txtSelectValues" MinWidth="250" Margin="0,0,0,0" ItemTemplate="{StaticResource DataTemplate1}" VerticalAlignment="Top" />
Found it. It's a bug with the AutoCompleteBox. When inside a scrollviewer control, the dropdown gets messed up and displayed in an incorrect position
Its not just that is also to do with being placed inside of a Pivot/Panaroma as well as the scrollviewer, the silverlight gurus have stated they haven't a timeline for the fix for the Pivot control, and there is a nasty hack
http://silverlight.codeplex.com/workitem/7574
I think the answer might just be that you shouldn't be using a ContentControl directly used like this. Try using something like a TextBlock instead - e.g.:
<DataTemplate x:Key="DataTemplate1">
<TextBlock Text="{Binding Name}" Margin="8,7"/>
</DataTemplate>
If that's not the answer, then try pulling back to a simple example - especially removing all the Margin's, Width's, Alignment's, etc - then put them back in one-by-one to work out and understand what is causing the effect you are seeing.

How to use Pivot Effectively?

I have following data structure in my WP7 app. And I'm generating three PivotItems through databinding, contents of binding. Interesting part is when Binding happens for Pivot items contents(Items) are queried for three time and again selection changes.
Is there anything I'm doing wrong?
Code:
<controls:Pivot Title="{StaticResource ApplicationName}" ItemsSource="{Binding Folders}" SelectedItem="{Binding SelectedFolder, Mode=TwoWay}" Name="_pivot">
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox DataContext="{Binding Source={StaticResource Locator}}" ItemsSource="{Binding ThingsListViewModel.Items}" />
</DataTemplate>
</controls:Pivot.ItemTemplate>
I have three folders items, when Pivot control is created ThingsListViewModel.Items property executed thrice, and once every time selection changes.
I'm expecting ThingsListViewModel.Items to execute only selection chage on Pivot control.
I think you need to listen to the LoadedPivotItem and Loaded events of the pivot. The Loaded event will always load the first PivotItem (LoadedPivotItem) will not be called. The LoadedPivotItem is called when the user swipes to another PivotItem.
Based on these events you should then run your queries for the currently SelectedPage. You may also want a flag to indicate once you have loaded the data for each Pivot to avoid running the queries again.

Categories