Introduction :
How to Move Telerik Rad Window in WPF
Descritption :
You can move your rad window move any where in your
page
Using Code :
In
Design View :
Hide
Expand
<Canvas Name="mycanvas" Height="{Binding Height,ElementName=radWindow2}" Width="{Binding Width,ElementName=radWindow2}" >
<Thumb DragDelta="Thumb_DragDelta" Height="20" Canvas.Top="0" Canvas.Left="0" Panel.ZIndex="2" Name="thumbh1" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" Width="243" MouseEnter="thumbh1_MouseEnter" MouseLeave="thumbh1_MouseLeave" Background="Transparent" >
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<telerik:RadWindow Name="radWindow2" Header="" Width="272" MinHeight="100" MinWidth="100" Height="110" Canvas.Top="0" Canvas.Left="0" CanClose="False" Panel.ZIndex="1" ResizeMode="NoResize" Visibility="Collapsed" BorderThickness="1" IsHeaderHitTestVisible="True" >
<telerik:RadWindow.HeaderTemplate>
<DataTemplate>
<DockPanel Width="{Binding Width,ElementName=radWindow2}" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel>
<TextBlock Text="RADWINDOW" FontSize="12" HorizontalAlignment="Left" Margin="0,5,0,2"></TextBlock>
</StackPanel>
<StackPanel Margin="0,0,14,0" >
<telerik:RadButton Content="X" FontSize="9" Width="25" Height="18" FontWeight="Bold" Click="RadButton_Click" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5,2,0,2"></telerik:RadButton>
</StackPanel>
</DockPanel>
</DataTemplate>
</telerik:RadWindow.HeaderTemplate>
<Grid >
<StackPanel Orientation="Vertical">
<TextBox Height="20" Width="80" Name="txtone"></TextBox>
<telerik:RadButton Content="Button" Height="Auto" HorizontalAlignment="Center" Name="radButton1" VerticalAlignment="Top" Width="Auto" Click="radButton1_Click" />
</StackPanel>
<Thumb DragDelta="thumbh3_DragDelta" Width="{Binding Width,ElementName=radWindow2}" Height="15" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh3" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh3_MouseEnter" MouseLeave="thumbh3_MouseLeave">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb DragDelta="thumbh4_DragDelta" Height="{Binding Height,ElementName=radWindow2}" HorizontalAlignment="Right" Panel.ZIndex="2" Name="thumbh4" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh4_MouseEnter" MouseLeave="thumbh4_MouseLeave" Width="10">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb DragDelta="thumbh5_DragDelta" HorizontalAlignment="Right" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh5" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh5_MouseEnter" MouseLeave="thumbh5_MouseLeave" Width="10">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</telerik:RadWindow>
</Canvas>
<Thumb DragDelta="Thumb_DragDelta" Height="20" Canvas.Top="0" Canvas.Left="0" Panel.ZIndex="2" Name="thumbh1" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" Width="243" MouseEnter="thumbh1_MouseEnter" MouseLeave="thumbh1_MouseLeave" Background="Transparent" >
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<telerik:RadWindow Name="radWindow2" Header="" Width="272" MinHeight="100" MinWidth="100" Height="110" Canvas.Top="0" Canvas.Left="0" CanClose="False" Panel.ZIndex="1" ResizeMode="NoResize" Visibility="Collapsed" BorderThickness="1" IsHeaderHitTestVisible="True" >
<telerik:RadWindow.HeaderTemplate>
<DataTemplate>
<DockPanel Width="{Binding Width,ElementName=radWindow2}" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel>
<TextBlock Text="RADWINDOW" FontSize="12" HorizontalAlignment="Left" Margin="0,5,0,2"></TextBlock>
</StackPanel>
<StackPanel Margin="0,0,14,0" >
<telerik:RadButton Content="X" FontSize="9" Width="25" Height="18" FontWeight="Bold" Click="RadButton_Click" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5,2,0,2"></telerik:RadButton>
</StackPanel>
</DockPanel>
</DataTemplate>
</telerik:RadWindow.HeaderTemplate>
<Grid >
<StackPanel Orientation="Vertical">
<TextBox Height="20" Width="80" Name="txtone"></TextBox>
<telerik:RadButton Content="Button" Height="Auto" HorizontalAlignment="Center" Name="radButton1" VerticalAlignment="Top" Width="Auto" Click="radButton1_Click" />
</StackPanel>
<Thumb DragDelta="thumbh3_DragDelta" Width="{Binding Width,ElementName=radWindow2}" Height="15" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh3" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh3_MouseEnter" MouseLeave="thumbh3_MouseLeave">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb DragDelta="thumbh4_DragDelta" Height="{Binding Height,ElementName=radWindow2}" HorizontalAlignment="Right" Panel.ZIndex="2" Name="thumbh4" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh4_MouseEnter" MouseLeave="thumbh4_MouseLeave" Width="10">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
<Thumb DragDelta="thumbh5_DragDelta" HorizontalAlignment="Right" VerticalAlignment="Bottom" Panel.ZIndex="2" Name="thumbh5" Visibility="{Binding Visibility,ElementName=radWindow2,Mode=TwoWay}" MouseEnter="thumbh5_MouseEnter" MouseLeave="thumbh5_MouseLeave" Width="10">
<Thumb.Template>
<ControlTemplate>
<TextBlock Text="" Background="Transparent"></TextBlock>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</telerik:RadWindow>
</Canvas>
In
Coding View :
private void Page_Loaded(object sender, RoutedEventArgs e)
{
thumbh3.DragDelta +=new System.Windows.Controls.Primitives.DragDeltaEventHandler(thumbh3_DragDelta);
}
public Icon icon { get; set; }
private void button1_Click(object sender, RoutedEventArgs e)
{
if (radWindow2.Visibility == Visibility.Collapsed)
{
radWindow2.Visibility = Visibility.Visible;
// SetCenter();
}
else
{
radWindow2.Visibility = Visibility.Collapsed;
//SetCenter();
}
}
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
movewindow(radWindow2, thumbh1, e);
}
public void movewindow(RadWindow radwindow, System.Windows.Controls.Primitives.Thumb thumb, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
Canvas.SetLeft(radwindow, Canvas.GetLeft(thumb) + e.HorizontalChange);
Canvas.SetTop(radwindow, Canvas.GetTop(thumb) + e.VerticalChange);
Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange);
Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange);
}
private void thumbh3_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Height > radWindow2.MinHeight)
{
radWindow2.Height += e.VerticalChange;
}
else{
radWindow2.Height = radWindow2.MinHeight + 4;
thumbh3.ReleaseMouseCapture();
}
}
private void thumbh3_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh3.Cursor = System.Windows.Input.Cursors.SizeNS;
}
private void thumbh3_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh3.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh1_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh1.Cursor = System.Windows.Input.Cursors.Hand;
}
private void thumbh1_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh1.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh4_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh4.Cursor = System.Windows.Input.Cursors.SizeWE;
}
private void thumbh4_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh4.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh4_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Width > radWindow2.MinWidth)
{
radWindow2.Width += e.HorizontalChange;
}
else
{
radWindow2.Width = radWindow2.MinWidth + 4;
thumbh4.ReleaseMouseCapture();
}
}
private void thumbh5_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh5.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh5_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh5.Cursor = System.Windows.Input.Cursors.SizeNWSE;
}
private void thumbh5_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Width > radWindow2.MinWidth)
{
if (e.HorizontalChange > 0)
{
radWindow2.Width += e.HorizontalChange;
}
else
{
radWindow2.Width = radWindow2.Width-4;
}
}
else
{
radWindow2.Width = radWindow2.MinWidth + 4;
}
if (radWindow2.Height > radWindow2.MinHeight)
{
if (e.VerticalChange > 0)
{
radWindow2.Height += e.VerticalChange;
}
else
{
radWindow2.Height = radWindow2.Height-4;
}
}
else
{
radWindow2.Height = radWindow2.MinHeight + 4;
}
}
private void RadButton_Click(object sender, RoutedEventArgs e)
{
closewindow(radWindow2);
}
public void closewindow(RadWindow radwindow)
{
radwindow.Visibility = Visibility.Collapsed;
}
Hide
Expand
{
thumbh3.DragDelta +=new System.Windows.Controls.Primitives.DragDeltaEventHandler(thumbh3_DragDelta);
}
public Icon icon { get; set; }
private void button1_Click(object sender, RoutedEventArgs e)
{
if (radWindow2.Visibility == Visibility.Collapsed)
{
radWindow2.Visibility = Visibility.Visible;
// SetCenter();
}
else
{
radWindow2.Visibility = Visibility.Collapsed;
//SetCenter();
}
}
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
movewindow(radWindow2, thumbh1, e);
}
public void movewindow(RadWindow radwindow, System.Windows.Controls.Primitives.Thumb thumb, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
Canvas.SetLeft(radwindow, Canvas.GetLeft(thumb) + e.HorizontalChange);
Canvas.SetTop(radwindow, Canvas.GetTop(thumb) + e.VerticalChange);
Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange);
Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange);
}
private void thumbh3_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Height > radWindow2.MinHeight)
{
radWindow2.Height += e.VerticalChange;
}
else{
radWindow2.Height = radWindow2.MinHeight + 4;
thumbh3.ReleaseMouseCapture();
}
}
private void thumbh3_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh3.Cursor = System.Windows.Input.Cursors.SizeNS;
}
private void thumbh3_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh3.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh1_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh1.Cursor = System.Windows.Input.Cursors.Hand;
}
private void thumbh1_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh1.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh4_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh4.Cursor = System.Windows.Input.Cursors.SizeWE;
}
private void thumbh4_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh4.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh4_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Width > radWindow2.MinWidth)
{
radWindow2.Width += e.HorizontalChange;
}
else
{
radWindow2.Width = radWindow2.MinWidth + 4;
thumbh4.ReleaseMouseCapture();
}
}
private void thumbh5_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh5.Cursor = System.Windows.Input.Cursors.Arrow;
}
private void thumbh5_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
thumbh5.Cursor = System.Windows.Input.Cursors.SizeNWSE;
}
private void thumbh5_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (radWindow2.Width > radWindow2.MinWidth)
{
if (e.HorizontalChange > 0)
{
radWindow2.Width += e.HorizontalChange;
}
else
{
radWindow2.Width = radWindow2.Width-4;
}
}
else
{
radWindow2.Width = radWindow2.MinWidth + 4;
}
if (radWindow2.Height > radWindow2.MinHeight)
{
if (e.VerticalChange > 0)
{
radWindow2.Height += e.VerticalChange;
}
else
{
radWindow2.Height = radWindow2.Height-4;
}
}
else
{
radWindow2.Height = radWindow2.MinHeight + 4;
}
}
private void RadButton_Click(object sender, RoutedEventArgs e)
{
closewindow(radWindow2);
}
public void closewindow(RadWindow radwindow)
{
radwindow.Visibility = Visibility.Collapsed;
}
0 comments:
Post a Comment