Cómo: WPF Mover la ventana con cualquier elemento

[y no necesariamente la barra de título]

Esto es lo más simple de todos los Cómo de WPF.

Al código del Post “Cómo WPF con Fondo Transparente” le agregaremos un evento para cuando se ‘mantenga pulsado el botón izquierdo del mouse” [en Chileno, para cuando pinchas y mantienes presionado..] MouseLeftButtonDown=”MoverVentana” Con lo que el código nos quedará


<window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication2.MainWindow"
x:Name="Window"
Title="MainWindow"
AllowsTransparency="True"
WindowStyle="None" ResizeMode="NoResize"
Width="640" Height="480" Background="{x:Null}">

<grid x:Name="LayoutRoot">
<ellipse Fill="#FF570C0C" Stroke="Black" Margin="232,124,60,101" Width="100" Height="100" MouseLeftButtonDown="MoverVentana"/>
</grid>
</window>

Pero debemos llamar a dicha Función/Método, por lo cuá en el código C# le agregarémos


public void MoverVentana(object sender, RoutedEventArgs e)
{
DragMove();
}

La función DragMove se encargará de mover la ventana, tal cuál lo dice la documentación de MSDN

y listo…

[al final de la serie armaré un demo con todo esto incluído]

Saludos

Cómo: WPF con fondo transparente

Cómo: WPF con fondo transparente

Siguiendo la línea de Cómo en WPF este tip te demostrará cómo crear una ventana con fondo transparente:

Para ello sólo debes agregar al Tag Window el parámetro AllowTransparency=”True” y sumándolo al post anterior de cómo realizar una ventana sin bordes con WPF nos queda este código:


<window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication2.MainWindow"
x:Name="Window"
Title="MainWindow"
AllowsTransparency="True"
WindowStyle="None" ResizeMode="NoResize"
Width="640" Height="480" Background="{x:Null}">

<grid x:Name="LayoutRoot">
<ellipse Fill="#FF570C0C" Stroke="Black" Margin="232,124,60,101" Width="100" Height="100"/>
</grid>
</window>

Ojalá les sirva de algo :)

Saludos

<Window
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
x:Class=”WpfApplication2.MainWindow”
x:Name=”Window”
Title=”MainWindow”
AllowsTransparency=”True”
WindowStyle=”None” ResizeMode=”NoResize”
Width=”640″ Height=”480″ Background=”{x:Null}”>

<Grid x:Name=”LayoutRoot”>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”0.82*”/>
<ColumnDefinition Width=”0.18*”/>
</Grid.ColumnDefinitions>
<Ellipse Fill=”#FF570C0C” Stroke=”Black” Margin=”232,124,60,101″/>
</Grid>
</Window>