2012-12-04 9 views
7

क्या डब्ल्यूपीएफ में कोई रास्ता है जहां मैं मुख्य विंडो की सीमा को हटा सकता हूं, फिर भी उस विंडो को आकार में बदलने की अनुमति देता है (पकड़ के बिना)?सीमा के बिना एक WPF विंडो कैसे बनाएं जिसका आकार बदला जा सकता है?

मुझे एहसास हुआ कि CanResizeWithGrip पर आकार बदलने के लिए इस परिदृश्य को करने का एक तरीका है। हालांकि, मैं इसे रीसाइज़ मोड के साथ CanResize पर सेट करने में सक्षम होना चाहता हूं।

मैं निम्नलिखित की स्थापना की कोशिश की:

ResizeMode="CanResize" 
WindowStyle="None" 
AllowsTransparency="True" 

हालांकि, AllowsTransparency की स्थापना करके, यह पकड़ के बिना आकार परिवर्तन करने की क्षमता को हटा। कोई विचार है कि मैं इसे कैसे खींच सकता हूं?

मुझे यह भी ध्यान रखना चाहिए कि मैं AllowsTransparency को किसी भी तरह से सही पर सेट नहीं कर सकता, क्योंकि मैं अपनी खिड़की में एक Winformshost नियंत्रण का उपयोग कर रहा हूं, जो AllowsTransparency सही नहीं है जब दिखाया गया है।

+0

मैं सिर्फ बजाय मेरी यूआई सुधार करने का फैसला किया, और सिर्फ ResizeMode = "CanResize" की स्थापना की और चातुर्य में सीमा छोड़ दिया है। – jsirr13

उत्तर

-5

सरल, लेकिन शायद बहुत आसान

this.MouseLeftButtonDown += delegate { this.DragMove(); }; 
+0

मैं जरूरी नहीं कि खिड़की को स्थानांतरित करना चाहता हूं, लेकिन केवल सीमा का आकार बदलता है (जिसे मैं अंत में छुपा चाहता हूं) खींचा जाता है। अनिवार्य रूप से मैं छिपे हुए सीमा के साथ, खिड़की का आकार बदलने के आम तौर पर व्यवहार का अनुकरण करना चाहता हूं। – jsirr13

+0

फिर आपको किनारे पर चलने वाले किनारे को कैप्चर करने और किनारे के आधार पर एक्स, वाई, डब्ल्यू, एच समायोजित करने की आवश्यकता होगी। – kenny

0

आप WPF अनुकूलन खिड़की पुस्तकालय का उपयोग कर सकते है, यहाँ उपलब्ध है: http://wpfwindow.codeplex.com/

तब, जब पुस्तकालय की खिड़की प्रकार का उपयोग कर, आप एक ही सेट कर सकते हैं गुणों के अनुसार

<CustomWindow:EssentialWindow x:Class="CustomWindowDemo.DemoEssentialWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:CustomWindow="clr-namespace:CustomWindow;assembly=CustomWindow" 
    AllowsTransparency="True" ResizeMode="CanResize" WindowStyle="None" Title="EssentialWindow" 
    Height="300" Width="250"> 
+0

उनकी साइट पर, यह कहता है: WPF विंडो का पूर्ण अनुकूलन तभी किया जा सकता है जब AllowTransparency को "True" पर सेट किया गया हो। फिर, दुर्भाग्य से मैं WinFormsHost बग के कारण इसका उपयोग नहीं कर सकता, जहां नियंत्रण ट्रांस्पेरेंसी को सत्य पर सेट होने पर नियंत्रण प्रदर्शित नहीं होता है। हो सकता है कि अगर मैं उस मुद्दे को पार कर सकता हूं, तो आपकी प्रतिक्रिया आदर्श समाधान के करीब होगी। – jsirr13

+0

@ jsirr13, मैंने कोशिश नहीं की है, लेकिन WinFormsHost बग को हल करने के तरीके पर एक समाधान है http://mrtncls.blogspot.com/2011/07/windowsformshost-on-transparent-wpf.html Win API के माध्यम से भी समाधान http: //www.neowin।नेट/फोरम/विषय/646970-सी% 23-wpf-window-with पारदर्शिता-बनाता-windowsformshost-गायब/ –

+0

मैंने दूसरे समाधान की कोशिश की, कोई किस्मत नहीं। मेरे पास समय होने पर पहला समाधान आज़माएगा। प्रतिक्रिया के लिए धन्यवाद। – jsirr13

1

उपयोगकर्ता को विंडो का आकार बदलने के लिए बातचीत करने की आवश्यकता है। यदि आपको डिफ़ॉल्ट सीमा या पकड़ पसंद नहीं है, तो आपको एक क्लिक और ड्रैग व्यवहार के साथ कुछ अन्य नियंत्रण जोड़ना होगा जो विंडो का आकार बदलता है। शायद खिड़की के प्रत्येक किनारे पर एक रेखा?

0

यह ResizeBorderThickness को 0 पर सेट है, तो हो सकता है

यह इस तरह XAML में एक सकारात्मक मान पर सेट किया जा सकता है:

<WindowChrome> 
    <WindowChrome.ResizeBorderThickness> 
     <Thickness>1</Thickness> 
    </WindowChrome.ResizeBorderThickness> 
</WindowChrome> 
5

मैं जानता हूँ कि यह एक पुराने सवाल है, लेकिन मैं तो बस चाहता था नवागंतुकों के लिए एक कामकाजी नमूना लगाने के लिए।

Xaml विंडो:

<Window x:Class="CustomWindowDemo.DemoCustomWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:CustomWindowDemo" 
     mc:Ignorable="d" 
     Title="DemoCustomWindow" Height="300" Width="300" Background="{x:Null}" AllowsTransparency="True" WindowStyle="None"> 
    <Window.Resources> 
     <Style x:Key="BorderThumb" TargetType="Thumb"> 
      <Setter Property="SnapsToDevicePixels" Value="true" /> 
      <Setter Property="OverridesDefaultStyle" Value="true" /> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="Thumb"> 
         <Rectangle MinWidth="4" MinHeight="4" StrokeThickness="0"> 
          <Rectangle.Fill> 
           <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" Opacity="0.05"/> 
          </Rectangle.Fill> 
         </Rectangle> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Window.Resources> 
    <Border BorderBrush="#55FFFFFF" BorderThickness="1" CornerRadius="5"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="Auto"/> 
        <ColumnDefinition/> 
        <ColumnDefinition Width="Auto"/> 
       </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition/> 
        <RowDefinition Height="Auto"/> 
       </Grid.RowDefinitions> 
      <Border MouseMove="Header_MouseMove" DockPanel.Dock="Top" Height="32" Grid.Row="1" Grid.Column="1"> 
        <Border.Background> 
         <LinearGradientBrush StartPoint="0,0" EndPoint="0,3"> 
          <GradientStop Color="#3BB2EA" Offset="0" /> 
          <GradientStop Color="#EFF7FA" Offset="0.3" /> 
         </LinearGradientBrush> 
        </Border.Background> 
        <Grid> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition/> 
          <ColumnDefinition Width="Auto"/> 
          <ColumnDefinition Width="Auto"/> 
          <ColumnDefinition Width="Auto"/> 
         </Grid.ColumnDefinitions> 
         <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0" Text="{Binding Path=Title, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/> 
         <Button x:Name="btn_Minimize" Background="{x:Null}" BorderBrush="{x:Null}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" Click="btn_Minimize_Click" Grid.Column="1"> 
          <Image Source="Resources/Ahmadhania-Spherical-Minimize.ico"/> 
         </Button> 
         <Button x:Name="btn_Maximize" Background="{x:Null}" BorderBrush="{x:Null}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" Grid.Column="2" Click="btn_Maximize_Click"> 
          <Image Source="Resources/1412181205_61002.ico"/> 
         </Button> 
         <Button x:Name="btn_Close" Background="{x:Null}" BorderBrush="{x:Null}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" Grid.Column="3" Click="btn_Close_Click"> 
          <Image Source="Resources/Ahmadhania-Spherical-Close(1).ico"/> 
         </Button> 
        </Grid> 
       </Border> 
      <Thumb x:Name="ThumbBottom" DragDelta="ThumbBottom_DragDelta" HorizontalAlignment="Stretch" Cursor="SizeNS" Grid.Column="0" Background="{x:Null}" Margin="3,0" Grid.ColumnSpan="3" Grid.Row="3" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Thumb x:Name="ThumbTop" DragDelta="ThumbTop_DragDelta" HorizontalAlignment="Stretch" Cursor="SizeNS" Grid.Column="0" Background="{x:Null}" Margin="3,0" Grid.ColumnSpan="3" Height="4" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Thumb x:Name="ThumbBottomRightCorner" DragDelta="ThumbBottomRightCorner_DragDelta" HorizontalAlignment="Right" Cursor="SizeNWSE" Grid.Row="3" Grid.Column="3" Background="{x:Null}" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Thumb x:Name="ThumbTopRightCorner" DragDelta="ThumbTopRightCorner_DragDelta" HorizontalAlignment="Right" Cursor="SizeNESW" Grid.Row="0" Grid.Column="2" Background="{x:Null}" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Thumb x:Name="ThumbTopLeftCorner" DragDelta="ThumbTopLeftCorner_DragDelta" HorizontalAlignment="Left" Cursor="SizeNWSE" Grid.Row="0" Grid.Column="0" Background="{x:Null}" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}" /> 
      <Thumb x:Name="ThumbBottomLeftCorner" DragDelta="ThumbBottomLeftCorner_DragDelta" HorizontalAlignment="Left" Cursor="SizeNESW" Grid.Row="3" Grid.Column="0" Background="{x:Null}" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}" /> 
      <Thumb x:Name="ThumbRight" DragDelta="ThumbRight_DragDelta" Cursor="SizeWE" Grid.Column="2" Grid.RowSpan="4" Background="{x:Null}" Margin="0,3" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Thumb x:Name="ThumbLeft" DragDelta="ThumbLeft_DragDelta" Cursor="SizeWE" Grid.Column="0" Grid.RowSpan="4" HorizontalContentAlignment="Right" Background="{x:Null}" Margin="0,3" Style="{Binding Mode=OneWay, Source={StaticResource BorderThumb}}"/> 
      <Grid x:Name="Grid_Content" Background="#EFF7FA" Grid.Row="2" Grid.Column="1"> 

      </Grid> 
     </Grid> 
    </Border> 
</Window> 

सी # के पीछे कोड:

using System.Windows.Interop; 
using winforms = System.Windows.Forms; 

namespace CustomWindowDemo 
{ 
    /// <summary> 
    /// Interaction logic for DemoCustomWindow.xaml 
    /// </summary> 
    public partial class DemoCustomWindow : Window 
    { 
     bool Maximized = false; 
     int NormalWidth = 0; 
     int NormalHeight = 0; 
     int NormalX = 0; 
     int NormalY = 0; 

     public DemoCustomWindow() 
     { 
      InitializeComponent(); 
     } 

     #region Header & Resize 
     void Header_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) 
     { 
      if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) 
       this.DragMove(); 
     } 

     void ThumbBottomRightCorner_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Width + e.HorizontalChange > 10) 
       this.Width += e.HorizontalChange; 
      if (this.Height + e.VerticalChange > 10) 
       this.Height += e.VerticalChange; 
     } 
     void ThumbTopRightCorner_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Width + e.HorizontalChange > 10) 
       this.Width += e.HorizontalChange; 
      if (this.Top + e.VerticalChange > 10) 
      { 
       this.Top += e.VerticalChange; 
       this.Height -= e.VerticalChange; 
      } 
     } 
     void ThumbTopLeftCorner_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Left + e.HorizontalChange > 10) 
      { 
       this.Left += e.HorizontalChange; 
       this.Width -= e.HorizontalChange; 
      } 
      if (this.Top + e.VerticalChange > 10) 
      { 
       this.Top += e.VerticalChange; 
       this.Height -= e.VerticalChange; 
      } 
     } 
     void ThumbBottomLeftCorner_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Left + e.HorizontalChange > 10) 
      { 
       this.Left += e.HorizontalChange; 
       this.Width -= e.HorizontalChange; 
      } 
      if (this.Height + e.VerticalChange > 10) 
       this.Height += e.VerticalChange; 
     } 
     void ThumbRight_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Width + e.HorizontalChange > 10) 
       this.Width += e.HorizontalChange; 
     } 
     void ThumbLeft_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Left + e.HorizontalChange > 10) 
      { 
       this.Left += e.HorizontalChange; 
       this.Width -= e.HorizontalChange; 
      } 
     } 
     void ThumbBottom_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Height + e.VerticalChange > 10) 
       this.Height += e.VerticalChange; 
     } 
     void ThumbTop_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
     { 
      if (this.Top + e.VerticalChange > 10) 
      { 
       this.Top += e.VerticalChange; 
       this.Height -= e.VerticalChange; 
      } 
     } 

     void btn_Minimize_Click(object sender, RoutedEventArgs e) 
     { 
      WindowState = WindowState.Minimized; 
     } 
     void btn_Maximize_Click(object sender, RoutedEventArgs e) 
     { 
      if (Maximized == true) 
      { 
       this.Width = NormalWidth; 
       this.Height = NormalHeight; 
       this.Left = NormalX; 
       this.Top = NormalY; 
       Maximized = false; 
       Thumbs(); 
      } 
      else 
      { 
       NormalX = (int)this.Left; 
       NormalY = (int)this.Top; 
       NormalHeight = (int)this.Height; 
       NormalWidth = (int)this.Width; 
       this.Left = winforms.Screen.FromHandle(new WindowInteropHelper(this).Handle).WorkingArea.Left; 
       this.Top = winforms.Screen.FromHandle(new WindowInteropHelper(this).Handle).WorkingArea.Top; 
       this.Width = winforms.Screen.FromHandle(new WindowInteropHelper(this).Handle).WorkingArea.Width; 
       this.Height = winforms.Screen.FromHandle(new WindowInteropHelper(this).Handle).WorkingArea.Height; 
       Maximized = true; 
       Thumbs(); 
      } 
     } 
     void btn_Close_Click(object sender, RoutedEventArgs e) 
     { 
      Close(); 
     } 
     void Thumbs() 
     { 
      if (Maximized == true) 
      { 
       ThumbBottom.Visibility = Visibility.Collapsed; 
       ThumbLeft.Visibility = Visibility.Collapsed; 
       ThumbTop.Visibility = Visibility.Collapsed; 
       ThumbRight.Visibility = Visibility.Collapsed; 
       ThumbTopLeftCorner.Visibility = Visibility.Collapsed; 
       ThumbTopRightCorner.Visibility = Visibility.Collapsed; 
       ThumbBottomLeftCorner.Visibility = Visibility.Collapsed; 
       ThumbBottomRightCorner.Visibility = Visibility.Collapsed; 
      } 
      else 
      { 
       ThumbBottom.Visibility = Visibility.Visible; 
       ThumbLeft.Visibility = Visibility.Visible; 
       ThumbTop.Visibility = Visibility.Visible; 
       ThumbRight.Visibility = Visibility.Visible; 
       ThumbTopLeftCorner.Visibility = Visibility.Visible; 
       ThumbTopRightCorner.Visibility = Visibility.Visible; 
       ThumbBottomLeftCorner.Visibility = Visibility.Visible; 
       ThumbBottomRightCorner.Visibility = Visibility.Visible; 
      } 
     } 
     #endregion 
    } 
} 
+0

जहां तक ​​मुझे याद है, वहां एक संपत्ति विंडो है। रेस्टोरबाउंड जो वास्तव में आकार का प्रतिनिधित्व करता है कि खिड़की सामान्य स्थिति में संक्रमण के बाद वापस आ जाएगी – Demarsch

संबंधित मुद्दे