2014-10-09 172 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

編碼快樂=)))