Hi I am building a custom Filtering Control which allows users to resize the control. Interacting with the thumbs to resize is working but,I have noticed that when i click on the main FilteringControl the whole Custom control will closes which means i can't filter my data :( . How can i stop this from occurring? Thanks in advance.
<UserControl x:Class="MyControls.Views.ResizableFilteringControl.ResizableFilteringControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="500" >
<UserControl.Resources>
</UserControl.Resources>
<Grid>
<StackPanel Margin="18" Background="White">
<telerik:FilteringControl Name="FilteringControl"></telerik:FilteringControl>
<Grid>
<Thumb Name="SouthEastThumb"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Width="16" Height="16"
MouseEnter="OnMouseEnter"
DragStarted="OnDragStarted"
DragDelta="OnDragDelta"
DragCompleted="OnDragCompleted"/>
<Thumb Name="SouthWestThumb"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="16" Height="16"
MouseEnter="OnMouseEnter"
DragStarted="OnDragStarted"
DragDelta="OnDragDelta"
DragCompleted="OnDragCompleted"/>
</Grid>
</StackPanel>
</Grid>
</UserControl>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
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 DevExpress.Xpf.Core;
using DevExpress.Xpf.Core.Native;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using GridViewColumn = Telerik.Windows.Controls.GridViewColumn;
namespace MyControls.Views.ResizableFilteringControl
{
/// <summary>
/// Interaction logic for ResizableFilteringControl.xaml
/// </summary>
public partial class ResizableFilteringControl : IFilteringControl
{
//TODO fix issue with control not remiaing open when i click on the FilteringControl.
//TODO add style to Thumbs.
public ResizableFilteringControl()
{
InitializeComponent();
}
public void Prepare(GridViewColumn columnToPrepare)
{
this.FilteringControl?.Prepare(columnToPrepare);
}
public bool IsActive
{
get { return (bool)GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); }
}
/// <summary>
/// Identifies the <see cref="IsActive"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(
"IsActive",
typeof(bool),
typeof(ResizableFilteringControl),
new System.Windows.PropertyMetadata(false));
private void OnDragStarted(object sender, DragStartedEventArgs e)
{
SetCursor(sender);
}
private void OnDragDelta(object sender, DragDeltaEventArgs e)
{
//TODO make resize to left.
var yadjust = FilteringControl.RenderSize.Height + e.VerticalChange;
var xadjust = this.FilteringControl.RenderSize.Width + e.HorizontalChange;
if (IsResizeAllowed(xadjust, yadjust))
{
this.FilteringControl.Width = xadjust;
this.FilteringControl.Height = yadjust;
}
}
private static bool IsResizeAllowed(double xadjust, double yadjust)
{
//TODO let consumer specify these values so they are not hard coded.
return (xadjust >= 50 && yadjust >= 50) &&
(xadjust <= 800 && yadjust <= 800);
}
private void OnDragCompleted(object sender, DragCompletedEventArgs e)
{
var t = (Thumb)sender;
t.Cursor = null;
}
private void OnMouseEnter(object sender, MouseEventArgs e)
{
SetCursor(sender);
}
private static void SetCursor(object sender)
{
var thumb = sender as Thumb;
if (thumb != null)
{
if (thumb.Name == "SouthWestThumb")
{
thumb.Cursor = Cursors.SizeNWSE;
}
else if (thumb.Name == "SouthEastThumb")
{
thumb.Cursor = Cursors.SizeNESW;
}
else
{
thumb.Cursor = null;
}
}
}
}
}