2011-12-30 9 views
1

Microsoft Expression Blend WPFでフォームを作成しました。フォームフィールドは書式設定された矩形上にあります。私がしたことは元のウィンドウを隠すことです。今では、アプリケーションを実行するとき以外は、マウスを使用してフォームを移動することはできません。これのための解決策は何でしょうか?シェイプウィンドウをマウスで移動可能にする

ここはスクリーンショットです。

enter image description here

答えて

1

この効果を達成するために、以下のことを試してみてください。ウィンドウ要素で

  1. なしにWindowStyleプロパティを設定します。
  2. [背景]を[NULL]に設定します。
  3. [透明度をTrueに設定]を設定します。

コンテンツをBorder要素内にグループ化します。この種の作業では、矩形よりも罫線がはるかに優れています。境界線で次のプロパティを設定します。

  1. 5~10%のアルファチャンネルを使用して、希望する色の背景を設定します。
  2. ボーダーブラシを希望の色にします。 (これのアルファチャンネルを設定したい場合もあれば、設定したくない場合もあります)
  3. 境界線の太さを希望の太さに設定します。

アプリを実行すると、おおよそOP状態になります。今度は、ウィンドウのドラッグを追加するには、Window上でMouseDownイベントをキャプチャし、DragMove()を呼び出すだけです。ここで

は、実行することができるはずサンプルWPFアプリです:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
    x:Class="ShapedWindow.MainWindow" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" 
    Height="480" 
    WindowStyle="None" 
    Background="{x:Null}" 
    AllowsTransparency="True" 
    MouseDown="Window_MouseDown"> 
<Border x:Name="LayoutRoot" 
     BorderBrush="Black" 
     CornerRadius="50" 
     BorderThickness="2,2,3,3" 
     Background="#18EF3B3B"> 
    <Grid> 
     <Button x:Name="CloseButton" 
       Content="Close" 
       HorizontalAlignment="Right" 
       VerticalAlignment="Top" 
       Width="75" 
       Margin="0,19,26,0" 
       Click="CloseButton_Click" /> 
    </Grid> 
</Border> 

そして、背後にあるコード:

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Shapes; 

namespace ShapedWindow 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      this.InitializeComponent(); 

      // Insert code required on object creation below this point. 
     } 

     private void CloseButton_Click(object sender, RoutedEventArgs e) 
     { 
      this.Close(); 
     } 

     private void Window_MouseDown(object sender, MouseButtonEventArgs e) 
     { 
      DragMove(); 
     } 
    } 
} 
関連する問題