Hi Guys,
Is it possible to drag out measures, columns and rows like the Xamdatagrid, with 'X" sign coming up. How do we make that to work here in the PivotGrid?
Cheers,
anand
Hello Anand,
This should be occurring by default when you drag out the measures, columns and rows. Please see my attached sample. When I add a measure or dimension and then try to remove it by dragging it out, the cursor is replaced with an X. Do you not see this?
Hey Rob,
It works like a charm!!! Duhh, Sorry I mistakenly overrode that. Sorry about that. Also is there any way we can change the look 'X' of the drag adorner?
Anand
Hi Anand,
This was a little tricky because of the way the pivotgrid handles the drag and drop. There is an internal class that the pivot grid uses for getting the required drag/drop templates and then it sets the appropriate template based on the current action. Since all of this is done internally there's no simple way to change the template that it uses.
What I managed to do was create a resource dictionary that takes the default template and slightly modifies the DragSource to include a DragStart event handler. I ended up needing to give the resource dictionary a code behind file as well in order to handle the event handler. Inside the event handler, I handled some more drag events and then I manually changed the drag template depending on what the mouse was over. The important thing to note here is that in order for this to work, the pivot grids internal drag/drop stuff needs to happen first. In order to ensure this I used a Dispatcher to hook up the events later. Now all you need to do is drop my resource dictionary into your project and then modify the DataTemplate called "removeItemDragCursorTemplate".
Rob thanks for your great work and this sample. How can I make this more similar to DataGrid's adorner preview and 'X' ?
The XamDataGrid's 'X' cursor is actually a change to the Mouse.Cursor itself. There is a .cur file that contains it. I took that file, converted it to png and added it as an image in the data template so it now appears to use the same 'X' icon.
Thanks Rob this works great, but two more questions here, I overrode the style of the FilterFieldItemControl to blackish theme. how do I override the light green/blue default color of the adorner. Also I have some a converter in my FieldItemTemplate, how can I make this adorner use this converted value. For the datagrid when I changed the label presenter it seemed to pick up that style. The pivot grid seemed to be diff that way. Any thoughts there.
Again, I appreciate all the effort you take to answer these questions. Thanks again !!
<DataTemplate x:Key="FieldItemTemplateKey1">
<Border Background="#00FFFFFF">
<TextBlock VerticalAlignment="Center" >
<TextBlock.Text>
<MultiBinding Converter="{StaticResource PivotConv}">
<Binding RelativeSource="{RelativeSource AncestorType=ig:XamPivotGrid}" Path="DataSource" >
</Binding>
<Binding Path="Caption"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Border>
</DataTemplate>
Thanks for your research in this..
It turns out that there is a separate template being used for dragging that you are seeing. It doesn't actually use the FilterFieldItemControl as the template for the drag. Unfortunately this template is also an internal template that is not exposed to developers. I tried to see if there was some way to override it using a similar approach as to what I used before with the 'X' icon but there were no good events for this. I had wanted to stay away from this other option as long as possible but based on the way we developed this I don't see another way.
The option I'm talking about is to use reflection to change the internal drag templates. Inside the pivot grid there is an internal class called PivotGridDataTemplates. Using reflection we can get the Type object for this class and then get it's fields. We need to get the fields and not the properties because the properties do not have any setters. And based on how the properties are setup, setting the fields directly would be better. Here is an example of one of the properties.
public static DataTemplate DragTemplate { get { if (_resources == null) { _resources = GetResources(); } if (_dragTemplate == null) { _dragTemplate = _resources["dragTemplate"] as DataTemplate; } return _dragTemplate; } }
As you can see, if _dragTemplate is not null then it won't get the DataTemplate from the resource dictionary. So if we set it before it tries to get the template then it will use our template instead of the default one from now on. Here is the code:
Assembly test = Assembly.GetAssembly(typeof(XamPivotGrid)); Type type = test.GetType("Infragistics.Controls.Grids.PivotGridDataTemplates"); FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Static); fields.ElementAt(1).SetValue(null, LayoutRoot.Resources["dragTemplate"] as DataTemplate);
"fields.ElementAt(1)" will give you the above _dragTemplate field and then set it to my own DataTemplate. You can do this when the window's Loaded event has fired. You can also use this approach for the 'X' icon instead of the way we did it before. For the remove icon, it will be fields.ElementAt(2).
Ah ok. I gotcha. I will take a look and get back to you.
No this is a custom dark theme.
I meant, change the background color of the drag adorner of when its dragged from FilterFieldItemControl. I know how to style the FilterFieldItemControl fine.
Even though I change the color of the filterfielditemcontrol, the drag adorner stays the same light blue/green color.
This is following where the FieldItemTemplate is used as ItemTemplate in ColumnsFieldDropAreaControl for example
<ssp:ColumnsFieldDropAreaControl Drop="ColumnsDropControl_Drop" AllowDrop="True" DockPanel.Dock="Right" Margin="2,0,0,0" FontWeight="Normal" x:Name="ColumnsDropArea" Grid.Column="0" Grid.Row="1" ItemTemplate="{StaticResource FieldItemTemplateKey1}" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataSource.Columns, Mode=TwoWay}" IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataSource.Columns.IsEditable}" />
What blackish theme do you mean? Is it one of the themes we provide?
Couldn't you just set the Background property in the FilterFieldItemControl style to change it's color? Unless you are referring to a different part of the control.
I don't quite understand what you mean by how you can make the FieldItemTemplate use your converted value. What converted value specifically? The result of your "PivotConv" converter? You seem to be using it in your example DataTemplate for the TextBlock.Text. Are you trying to use it elsewhere?