2014-10-09 123 views
0

我有一个无边框设计的WPF Mdi窗口,我希望它是可移动的。 我尝试了我在Google上发现的所有内容,但没有任何内容适用于我的案例。这是可能的WPF无边框窗口?谢谢=)可移动的WPF无边界窗口

这是我如何让我的窗口无边界。

<pbwpf:Window x:Class="w_main" x:ClassModifier="internal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:pbwpf="clr-namespace:Sybase.PowerBuilder.WPF.Controls;assembly=Sybase.PowerBuilder.WPF.Controls" Uid="30" WindowStyle="None" AllowsTransparency="True" Background="Transparent" MenuName="m_menu" WindowType="Mdi" xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" VirtualizingStackPanel.VirtualizationMode="Recycling" xmlns:sys="clr-namespace:System;assembly=mscorlib" Center="True" ResizeMode="CanResize" Height="740" Width="1024" WindowState="Maximized" Resizable="True" ControlMenu="True"> 
    <Grid SnapsToDevicePixels="True" Height="700" Width="1009"> 
     <Grid.Effect> 
      <DropShadowEffect Color="Black" BlurRadius="15" Direction="721" ShadowDepth="1" RenderingBias="Quality" /> 
     </Grid.Effect> 
     <Border Background="White" /> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="50" /> 
       <RowDefinition Height="*" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="90" /> 
       <ColumnDefinition Width="680" /> 
       <ColumnDefinition Width="69" /> 
       <ColumnDefinition Width="170" /> 
      </Grid.ColumnDefinitions> 
      <Border Grid.Column="0" Grid.Row="0"> 
       <Image Source="Images/sample_bms.png" VerticalAlignment="Center" HorizontalAlignment="Center"></Image> 
      </Border> 
      <Border UseLayoutRounding="True" Grid.Row="0" Grid.Column="2" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="1,0,1,1"> 
       <Grid> 
        <Button Name="button_lgout" IsCancel="True"> 
         <Button.Style> 
          <Style TargetType="Button"> 
           <Setter Property="Background" Value="Transparent" /> 
           <Setter Property="Foreground" Value="White" /> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type Button}"> 
              <Border Background="{TemplateBinding Background}"> 
               <ContentPresenter TextElement.Foreground="{TemplateBinding Foreground}" /> 
              </Border> 
              <ControlTemplate.Triggers> 
               <Trigger Property="IsMouseOver" Value="true"> 
                <Setter Property="Background" Value="#2000" /> 
               </Trigger> 
              </ControlTemplate.Triggers> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
          </Style> 
         </Button.Style> 
         <StackPanel HorizontalAlignment="Center"> 
          <Image Source="Images/logout.png" Height="21" HorizontalAlignment="Center" Margin="0,5,0,0" /> 
          <Label Name="lbl_lgout" Content="LOGOUT" FontSize="12" Foreground="White" FontFamily="Calibri" HorizontalAlignment="Center" Height="27" /> 
         </StackPanel> 
        </Button> 
       </Grid> 
      </Border> 
      <Border Grid.Row="0" Grid.Column="3" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="0,0,0,1"> 
       <Grid VerticalAlignment="Center"> 
        <Image Source="Images/user_male2-32.png" UseLayoutRounding="True" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,18,0" Height="25" /> 
        <pbwpf:SingleLineEdit Name="txt_user" FontFamily="Calibri" FontSize="22" Foreground="White" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,52,0" Width="98" Height="30" PBHeight="120" DisplayOnly="True" /> 
       </Grid> 
      </Border> 
      <Border Grid.Row="0" Grid.Column="1" Background="#2cb6d9" BorderBrush="#25a6c7" BorderThickness="0,0,0,1" /> 
      <Border Grid.Row="1" Grid.Column="0" Background="#dedede" BorderBrush="#d9dcdf" BorderThickness="0,0,1,0"> 
       <StackPanel Orientation="Vertical" Height="750" Background="#111111"> 
        <StackPanel.Resources> 
         <Style TargetType="my:RibbonButton"> 
          <Style.Resources> 
           <sys:Double x:Key="buttonSize">60</sys:Double> 
           <CornerRadius x:Key="buttonRadius">30</CornerRadius> 
           <sys:Double x:Key="scaleOffset">30</sys:Double> 
          </Style.Resources> 
          <Setter Property="Margin" Value="0,10,0,0" /> 
          <Setter Property="Foreground" Value="White" /> 
          <Setter Property="FontSize" Value="20" /> 
          <Setter Property="FontWeight" Value="SemiBold" /> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="my:RibbonButton"> 
             <Border Background="Transparent" Width="{StaticResource buttonSize}" Height="{StaticResource buttonSize}" CornerRadius="{StaticResource buttonRadius}"> 
              <Grid> 
               <Border Background="#22ffffff" CornerRadius="{StaticResource buttonRadius}" x:Name="content"> 
                <Image Height="27" x:Name="image" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" Source="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"></Image> 
               </Border> 
               <Ellipse x:Name="ring" StrokeThickness="15" Opacity="0" IsHitTestVisible="False"> 
                <Ellipse.Stroke> 
                 <RadialGradientBrush> 
                  <GradientStop Color="Transparent" Offset="0.83" /> 
                  <GradientStop Color="LightGray" Offset="0.84" /> 
                  <GradientStop Color="Transparent" Offset="0.85" /> 
                  <GradientStop Color="Transparent" Offset=".93" /> 
                  <GradientStop Color="#55ffffff" Offset=".97" /> 
                  <GradientStop Color="#55ffffff" Offset="1" /> 
                 </RadialGradientBrush> 
                </Ellipse.Stroke> 
                <Ellipse.RenderTransform> 
                 <ScaleTransform CenterX="{StaticResource scaleOffset}" CenterY="{StaticResource scaleOffset}" x:Name="ringScale" /> 
                </Ellipse.RenderTransform> 
               </Ellipse> 
              </Grid> 
             </Border> 
             <ControlTemplate.Triggers> 
              <Trigger Property="IsMouseOver" Value="true"> 
               <Setter Property="Opacity" Value="0.2" /> 
               <Setter TargetName="content" Property="RenderTransform"> 
                <Setter.Value> 
                 <ScaleTransform CenterX="{StaticResource scaleOffset}" CenterY="{StaticResource scaleOffset}" ScaleX=".9" ScaleY=".9" /> 
                </Setter.Value> 
               </Setter> 
               <Setter Property="Opacity" Value="1" /> 
               <Trigger.EnterActions> 
                <BeginStoryboard> 
                 <Storyboard Duration="0:0:2"> 
                  <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ring" To="1" Duration="0:0:0" /> 
                  <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ring" From="1" To="0" /> 
                  <DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ringScale" From="1" To="1.5" /> 
                  <DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ringScale" From="1" To="1.5" /> 
                 </Storyboard> 
                </BeginStoryboard> 
               </Trigger.EnterActions> 
              </Trigger> 
             </ControlTemplate.Triggers> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </StackPanel.Resources> 
        <my:RibbonButton Name="rb_new" Margin="0,50,0,0" Content="Images/new_light.png" KeyTip="N" /> 
        <pbwpf:StaticText Name="st_new" Text="_New" Foreground="#eeeeee" Margin="33,-20,0,0" FontFamily="Calibri" /> 
        <my:RibbonButton Name="rb_edit" Margin="0,10,0,0" Content="Images/edit_light.png" KeyTip="E" /> 
        <pbwpf:StaticText Name="st_edit" Text="_Edit" Foreground="#eeeeee" Margin="33,-20,0,0" FontFamily="Calibri" PBWidth="402" Width="88" PBHeight="84" Height="21" /> 
        <my:RibbonButton Name="rb_save" Margin="0,10,0,0" Content="Images/save_light.png" KeyTip="S" /> 
        <pbwpf:StaticText Name="st_save" Text="_Save" Foreground="#eeeeee" Margin="33,-20,0,0" FontFamily="Calibri" PBWidth="402" Width="88" PBHeight="84" Height="21" /> 
        <my:RibbonButton Name="rb_abort" Margin="0,10,0,0" Content="Images/cancel_light.png" KeyTip="A" /> 
        <pbwpf:StaticText Name="st_abort" Text="_Abort" Foreground="#eeeeee" Margin="33,-21,0,0" FontFamily="Calibri" PBWidth="402" Width="88" PBHeight="84" Height="21" /> 
        <my:RibbonButton Name="rb_trash" Margin="0,10,0,0" Content="Images/delete_light.png" KeyTip="D" /> 
        <pbwpf:StaticText Name="st_trash" Text="_Trash" Foreground="#eeeeee" Margin="33,-21,0,0" FontFamily="Calibri" PBHeight="84" PBWidth="402" Width="88" /> 
        <my:RibbonButton Name="rb_print" Margin="0,10,0,0" Content="Images/print_light.png" KeyTip="P" /> 
        <pbwpf:StaticText Name="st_print" Text="_Print" Foreground="#eeeeee" Margin="33,-21,0,0" FontFamily="Calibri" PBHeight="84" PBWidth="0" Width="Auto" /> 
        <my:RibbonButton Name="rb_search" Margin="0,10,0,0" Content="Images/search_light.png" Visibility="Hidden" /> 
       </StackPanel> 
      </Border> 
      <Border Grid.Row="1" Grid.Column="1"> 
       <pbwpf:MDIClient Visibility="Visible" Name="mdi_1" Margin="0" Background="#ffffff" Width="920" /> 
      </Border> 
     </Grid> 
    </Grid> 
</pbwpf:Window> 

回答

5

这就是我所做的。

吉姆

在XAML

WindowStyle="None" AllowsTransparency="False" MouseDown="Window_MouseDown" ResizeMode="NoResize" 

在后面的代码

private void Window_MouseDown(object sender, MouseButtonEventArgs e) 
    { 
     if (e.LeftButton == MouseButtonState.Pressed) 
     { 
      DragMove(); 
     } 
    } 
+0

嗨@Jim感谢您的回答=),但目前我发现我如何使它的工作方式。当我使用电源构建器时,我把这个代码发送(处理(this),274,61458,0)在鼠标按下事件上,然后就是这样=)。无论如何感谢时间=))) – 2014-10-09 09:44:42

+1

我的荣幸。很高兴你对你的情况有一个回答:) – Jim 2014-10-09 10:49:57

0

作为我来说,我正在使用的PowerBuilder 12.5。所以这里有一个快速提示,如果你想让你的WPF无边界窗口可移动。

只是把这个代码在MouseDown事件: 发送(句柄(本),274,61458,0)

如果控制不具有鼠标按下事件则定义事件为: ue_mousedown pbm_lbuttondown

此答案来自http://eric.aling.tripod.com/PB/pbfaq.htm

编码快乐=)))