or
<!-- Style for Button --> |
<Style TargetType="Controls:RadDropDownButton" x:Key="DefaultButtonStyle"> |
<Setter Property="Background" Value="Transparent" /> |
<Setter Property="Foreground" Value="#FFFFFFFF" /> |
<Setter Property="Padding" Value="3" /> |
<Setter Property="BorderThickness" Value="1" /> |
<Setter Property="VerticalContentAlignment" Value="Center" /> |
<Setter Property="HorizontalContentAlignment" Value="Center" /> |
<Setter Property="BorderBrush" Value="Transparent" /> |
<Setter Property="Cursor" Value="Hand" /> |
<Setter Property="Template"> |
<Setter.Value> |
<ControlTemplate TargetType="Controls:RadDropDownButton"> |
<Grid Margin="0 0 0 5"> |
<Border x:Name="Background" BorderBrush="#FFBF97F2" |
BorderThickness="1,1,1,1" CornerRadius="4,4,4,4"> |
<Border.Background> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#FF3B2555" /> |
<GradientStop Color="#FF2B1C3C" Offset="0.61699998378753662" /> |
<GradientStop Color="#FF321F47" Offset="1" /> |
</LinearGradientBrush> |
</Border.Background> |
<Path x:Name="Path" Height="Auto" Margin="0,0.082,0,8.859" Width="Auto" |
Stretch="Fill" Stroke="{x:Null}" StrokeLineJoin="Round" |
StrokeThickness="1" |
Data="M0,3 C0,1.3431457 1.3431457,0 3,0 L129,0 C130.65686,0 132,1.3431457 132,3 L132,13.853975 C86.718803,0.055481441 26.160202,27.400364 0,11.585506 z"> |
<Path.Fill> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#005B3D7A" Offset="0.092" /> |
<GradientStop Color="#FF5B3D7A" Offset="1" /> |
</LinearGradientBrush> |
</Path.Fill> |
</Path> |
</Border> |
<ContentPresenter VerticalAlignment="Center" |
HorizontalAlignment="Center" |
Content="{TemplateBinding Content}" |
ContentTemplate="{TemplateBinding ContentTemplate}"/> |
</Grid> |
<ControlTemplate.Triggers> |
<Trigger Property="IsMouseOver" Value="true"> |
<Setter Property="BorderBrush" TargetName="Background" Value="#FFFFFFFF" /> |
<Setter Property="Fill" TargetName="Path"> |
<Setter.Value> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#005B3D7A" Offset="0.092" /> |
<GradientStop Color="#FF6D4497" Offset="1" /> |
</LinearGradientBrush> |
</Setter.Value> |
</Setter> |
</Trigger> |
<Trigger Property="IsPressed" Value="True" /> |
<Trigger Property="IsEnabled" Value="False" /> |
<Trigger Property="IsFocused" Value="False" /> |
</ControlTemplate.Triggers> |
</ControlTemplate> |
</Setter.Value> |
</Setter> |
</Style> |
I’m using the rowdragdrop example inside of a viewbox. Theviewbox is set to stretch=”Fill”. The problem I’m having is that when the userresizes the window and moves a row the offset inside the viewbox isn’t changingwhich means the position of the row that I’m dragging isn’t under the mouse.
I was wondering if you had any ideas on how this could befixed?
Thanks
~Boots
<Window x:Class="WpfApplication1.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerk="http://schemas.telerik.com/2008/xaml/presentation" |
xmlns:local="clr-namespace:WpfApplication1"> |
<Grid> |
<telerk:RadGridView x:Name="rgv" local:GridViewHeaderMenu.IsEnabled="True" /> |
</Grid> |
</Window> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Data; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Imaging; |
using System.Windows.Navigation; |
using System.Windows.Shapes; |
using System.Collections; |
namespace WpfApplication1 |
{ |
/// <summary> |
/// Interaction logic for Window1.xaml |
/// </summary> |
public partial class Window1 : Window |
{ |
public Window1() |
{ |
InitializeComponent(); |
ArrayList List = new ArrayList(); |
for (int i = 0; i < 100; i++) |
{ |
List.Add(new Testing() |
{ |
Test1 = i.ToString(), |
Test2 = i, |
Test3 = i, |
Test4 = i.ToString(), |
Test5 = i, |
Test6 = i, |
Test7 = i.ToString(), |
Test8 = i, |
Test9 = i, |
Test10 = i.ToString(), |
Test11 = i, |
Test12 = i, |
Test13 = i.ToString(), |
Test14 = i, |
Test15 = i, |
Test16 = i.ToString(), |
Test17 = i, |
Test18 = i |
}); |
} |
rgv.ItemsSource = List; |
} |
} |
public class Testing |
{ |
public String Test1 { get; set; } |
public int Test2 { get; set; } |
public Double Test3 { get; set; } |
public String Test4 { get; set; } |
public int Test5 { get; set; } |
public Double Test6 { get; set; } |
public String Test7 { get; set; } |
public int Test8 { get; set; } |
public Double Test9 { get; set; } |
public String Test10 { get; set; } |
public int Test11 { get; set; } |
public Double Test12 { get; set; } |
public String Test13 { get; set; } |
public int Test14 { get; set; } |
public Double Test15 { get; set; } |
public String Test16 { get; set; } |
public int Test17 { get; set; } |
public Double Test18 { get; set; } |
} |
} |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.ComponentModel; |
using System.Text; |
using System.Windows; |
using System.Windows.Data; |
using Telerik.Windows; |
using Telerik.Windows.Controls; |
using Telerik.Windows.Controls.GridView; |
using Telerik.Windows.Data; |
namespace WpfApplication1 |
{ |
public class GridViewHeaderMenu |
{ |
private RadGridView grid = null; |
public GridViewHeaderMenu(RadGridView grid) |
{ |
this.grid = grid; |
} |
public static readonly DependencyProperty IsEnabledProperty |
= DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(GridViewHeaderMenu), |
new PropertyMetadata(new PropertyChangedCallback(OnIsEnabledPropertyChanged))); |
public static void SetIsEnabled(DependencyObject dependencyObject, bool enabled) |
{ |
dependencyObject.SetValue(IsEnabledProperty, enabled); |
} |
public static bool GetIsEnabled(DependencyObject dependencyObject) |
{ |
return (bool)dependencyObject.GetValue(IsEnabledProperty); |
} |
private static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) |
{ |
RadGridView grid = dependencyObject as RadGridView; |
if (grid != null) |
{ |
if ((bool)e.NewValue) |
{ |
// Create new GridViewHeaderMenu and attach RowLoaded event. |
GridViewHeaderMenu menu = new GridViewHeaderMenu(grid); |
menu.Attach(); |
} |
} |
} |
private void Attach() |
{ |
if (grid != null) |
{ |
this.grid.Loaded += new RoutedEventHandler(grid_Loaded); |
} |
} |
void grid_Loaded(object sender, RoutedEventArgs e) |
{ |
GridViewHeaderRow headerRow = grid.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault(); |
if (headerRow != null) |
{ |
InitializeMenus(headerRow); |
} |
} |
private void InitializeMenus(GridViewHeaderRow row) |
{ |
IEnumerable<GridViewHeaderCell> cells = row.Cells.OfType<GridViewHeaderCell>(); |
foreach (GridViewHeaderCell cell in cells) |
{ |
// create menu |
RadContextMenu contextMenu = new RadContextMenu(); |
// set menu Theme |
StyleManager.SetTheme(contextMenu, StyleManager.GetTheme(grid)); |
RadMenuItem item = new RadMenuItem() { Header = String.Format(@"Sort Ascending by ""{0}""", cell.Column.Header) }; |
contextMenu.Items.Add(item); |
item = new RadMenuItem() { Header = String.Format(@"Sort Descending by ""{0}""", cell.Column.Header) }; |
contextMenu.Items.Add(item); |
item = new RadMenuItem() { Header = String.Format(@"Clear Sorting by ""{0}""", cell.Column.Header) }; |
contextMenu.Items.Add(item); |
item = new RadMenuItem() { Header = String.Format(@"Group by ""{0}""", cell.Column.Header) }; |
contextMenu.Items.Add(item); |
item = new RadMenuItem() { Header = String.Format(@"Ungroup ""{0}""", cell.Column.Header) }; |
contextMenu.Items.Add(item); |
item = new RadMenuItem() { Header = "Choose Columns:" }; |
contextMenu.Items.Add(item); |
// create menu items |
foreach (GridViewColumn column in grid.Columns) |
{ |
RadMenuItem subMenu = new RadMenuItem() |
{ |
Header = column.Header, |
IsCheckable = true, |
IsChecked = true |
}; |
// bind IsChecked menu item property to IsVisible column property |
subMenu.SetBinding(RadMenuItem.IsCheckedProperty, |
new Binding("IsVisible") { Mode = BindingMode.TwoWay, Source = column }); |
item.Items.Add(subMenu); |
} |
contextMenu.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick)); |
// attach menu |
RadContextMenu.SetContextMenu(cell, contextMenu); |
} |
} |
void OnMenuItemClick(object sender, RoutedEventArgs e) |
{ |
RadContextMenu menu = (RadContextMenu)sender; |
RadMenuItem clickedItem = ((RadRoutedEventArgs)e).OriginalSource as RadMenuItem; |
GridViewColumn column = ((GridViewHeaderCell)menu.UIElement).Column; |
if (clickedItem.Parent is RadMenuItem) |
return; |
string header = Convert.ToString(clickedItem.Header); |
using (grid.DeferRefresh()) |
{ |
Telerik.Windows.Data.SortDescriptor sd = (from d in grid.SortDescriptors |
where d.Member == column.UniqueName |
select d).FirstOrDefault(); |
if (header.Contains("Sort Ascending")) |
{ |
if (sd != null) |
{ |
grid.SortDescriptors.Remove(sd); |
} |
grid.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor() |
{ |
Member = column.UniqueName, |
SortDirection = ListSortDirection.Ascending |
}); |
} |
else if (header.Contains("Sort Descending")) |
{ |
if (sd != null) |
{ |
grid.SortDescriptors.Remove(sd); |
} |
grid.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor() |
{ |
Member = column.UniqueName, |
SortDirection = ListSortDirection.Descending |
}); |
} |
else if (header.Contains("Clear Sorting")) |
{ |
if (sd != null) |
{ |
grid.SortDescriptors.Remove(sd); |
} |
} |
else if (header.Contains("Group by")) |
{ |
Telerik.Windows.Data.GroupDescriptor gd = (from d in grid.GroupDescriptors |
where d.Member == column.UniqueName |
select d).FirstOrDefault(); |
if (gd == null) |
{ |
grid.GroupDescriptors.Add(new Telerik.Windows.Data.GroupDescriptor() { Member = column.UniqueName, SortDirection = ListSortDirection.Ascending }); |
} |
} |
else if (header.Contains("Ungroup")) |
{ |
Telerik.Windows.Data.GroupDescriptor gd = (from d in grid.GroupDescriptors |
where d.Member == column.UniqueName |
select d).FirstOrDefault(); |
if (gd != null) |
{ |
grid.GroupDescriptors.Remove(gd); |
} |
} |
} |
} |
} |
} |