本文介绍了定义最小规模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Iim使用操作来扩展我的用户控件。我想知道如何 申请最小规模 。我的意思是,我不想减少我的用户控制权 更多 比我的usercontrol min widht和min height。 这是我的申请: xaml: usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Windows; usingSystem.Windows.Controls; usingSystem.Windows.Data; usingSystem.Windows.Documents; usingSystem .Windows.Input; usingSystem.Windows.Media; usingSystem.Windows.Media.Imaging; usingSystem.Windows.Shapes; usingSystem.Windows.Threading; usingMicrosoft.Surface; usingMicrosoft.Surface.Presentation; usingMicrosoft.Surface.Presentation.Controls; usingMicrosoft .Surface.Presentation.Manipulations; usingSystem.Windows.Interop; namespace {teste2 ///< summary> /// $ SurfaceWindow {///< summary> /// Default constructor.///</summary>/// #region Class $ MembersList< Contact> downContacts; doublelastExpansionDelta; Affine2DManipulationProcessormanipulationProcessor; Affine2DInertiaProcessorinertiaProcessor; #endregion #regionProperties #regage $ { } ZoomSensitivity DPpublicdoubleZoomSensitivityget { return(double)GetValue(ZoomSensitivityProperty); } set { SetValue(ZoomSensitivityProperty,value); } //使用DependencyProperty作为ZoomSensitivity的后备存储。这样可以实现动画,样式,装订, 等... publicstaticreadonlyDependencyPropertyZoomSensitivityProperty = DependencyProperty.Register(" ZoomSensitivity",typeof(double), typeof(SurfaceWindow1),newUIPropertyMetadata(6.0)); #endregion #region { } PanSensitivity DPpublicdoublePanSensitivityget { return(double)GetValue(PanSensitivityProperty); } set { SetValue(PanSensitivityProperty,value); //使用DependencyProperty作为PanSensitivity的后备存储。这样可以实现动画,样式,装订, 等... publicstaticreadonlyDependencyPropertyPanSensitivityProperty = DependencyProperty.Register("PanSensitivity",typeof(double), typeof(SurfaceWindow1),newUIPropertyMetadata(1.0)); #endregion #region { } TiltSensitivity DPpublicdoubleTiltSensitivityget { return(double)GetValue(TiltSensitivityProperty); } set { SetValue(TiltSensitivityProperty,value); //使用DependencyProperty作为PanSensitivity的后备存储。这样可以实现动画,样式,装订, 等... publicstaticreadonlyDependencyPropertyTiltSensitivityProperty = DependencyProperty.Register(" TiltSensitivity",typeof(double), typeof(SurfaceWindow1),newUIPropertyMetadata(0.5));#endregion #endregion { InitializeComponent(); lastExpansionDelta = 0; downContacts = targetImage.AddHandler( targetImage.AddHandler( targetImage.AddHandler(publicSurfaceWindow1) ()newList< Contact>(); this.manipulationProcessor = newAffine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Scale ,this,false); this.manipulationProcessor.Affine2DManipulationCompleted + = newEventHandler< Affine2DOperationCompletedEventArgs>(manipulationProcessor_Affine2DManipulationCompleted); this.manipulationProcessor.Affine2DManipulationDelta + = newEventHandler< Affine2DOperationDeltaEventArgs>(manipulationProcessor_Affine2DManipulationDelta); this.manipulationProcessor.Affine2DManipulationStarted + = newEventHandler< Affine2DOperationStartedEventArgs>(manipulationProcessor_Affine2DManipulationStarted); this.inertiaProcessor = newAffine2DInertiaProcessor(); this.inertiaProcessor.Affine2DInertiaDelta + = newEventHandler< Affine2DOperationDeltaEventArgs>(inertiaProcessor_Affine2DInertiaDelta); this.inertiaProcessor.Affine2DInertiaCompleted + = newEventHandler< Affine2DOperationCompletedEventArgs>(inertiaProcessor_Affine2DInertiaCompleted); Contacts.PreviewContactDownEvent,$ newContactEventHandler(targetImage_PreviewContactDown)); Contacts.PreviewContactChangedEvent, ,$ newContactEventHandler(targetImage_PreviewContactChanged)); Contacts.PreviewContactUpEvent, newContactEventHandler(targetImage_PreviewCo) ntactUp)); //添加处理器为应用程序激活eventsAddActivationHandlers(); } ///< summary> / //窗口即将关闭时发生。 ///< / summary> ///< param name =" e">< / param> {protectedoverridevoidOnClosed(EventArgse)base.OnClosed(e) ; // 删除应用程序激活事件的处理程序.RemoveActivationHandlers(); } ///< summary> ///为应用程序激活添加处理程序 events.///</summary>{privatevoidAddActivationHandlers()//订阅表面 申请激活事件} ApplicationLauncher.ApplicationActivated + = OnApplicationActivated; ApplicationLauncher.ApplicationPreviewed + = OnApplicationPreviewed; ApplicationLauncher.ApplicationDeactivated + = OnApplicationDeactivated; ///< summary> ///删除Application的处理程序 激活事件///</summary>{privatevoidRemoveActivationHandlers()// 取消订阅表面应用程序激活 events} ApplicationLauncher。 ApplicationActivated - = OnApplicationActivated; Applicatio nLauncher.ApplicationPreviewed - = $ OnApplicationPreviewed; ApplicationLauncher.ApplicationDeactivated - = $ OnApplicationDeactivated; ///< summary> ///当应用程序为$ b $时调用b 已激活.// /&tt;/summary>///<param name =" sender">< / param> ///< param name =" e">< / param> {privatevoidOnApplicationActivated(objectsender, EventArgse)// TODO:启用音频,动画此处} ///< summary> ; ///当应用程序处于预览模式时,这称为 .///</summary>///<param name = " sender">< / param> ///< param name =" e">< / param> {privatevoidOnApplicationPreviewed(objectsender, EventArgse)// TODO:如果已启用音频,则禁用此处// TODO:可选启用此处动画} ///< summary> ///当应用程序已经 deactivated.///</summary>///<param name =" sender">< / param> ///< param name =" e">< / param> {privatevoidOnApplicationDeactivated(objectsender, EventArgse)// TODO:禁用音频,动画在这里} #region { } { } { } { ProcessManipulationInertiaDelta(e); }惯性处理器事件 HandlersvoidinertiaProcessorZoom_Affine2DInertiaCompleted(objectsender, Affine2DOperationCompletedEventArgse)voidinertiaProcessorZoom_Affine2DInertiaDelta(objectsender, Affine2DOperationDeltaEventArgse)voidinertiaProcessor_Affine2DInertiaCompleted(objectsender, , Affine2DOperationCompletedEventArgse)voidinertiaProcessor_Affine2DInertiaDelta(objectsender, Affine2DOperationDeltaEventArgse)#endregion #region { inertiaProcessor.End(); } { ProcessManipulationInertiaDel ta(e); } { containerRect.Width = 1024; containerRect.Height = 798;   ; $   ; $ { 矩阵= transformMatrix.Matrix; } matrix.Translate(-e.Delta.X,-e.Delta.Y); { b $ b transformCenter = matrix .Transform(transformCenter); matrix.RotateAt(e.RotationDelta,transformCenter.X,transformCenter.Y); matrix.ScaleAt(e.ScaleDelta,e.ScaleDelta ,transformCenter.X, transformCenter.Y); } targetImage.RenderTransform = } { } Ma nipulation处理器事件 HandlersvoidmanipulationProcessor_Affine2DManipulationStarted(objectsender, Affine2DOperationStartedEventArgse)voidmanipulationProcessor_Affine2DManipulationDelta(objectsender, Affine2DOperationDeltaEventArgse)privatevoidProcessManipulationInertiaDelta(Affine2DOperationDeltaEventArgse)RectcontainerRect t = newRect(this.RenderSize); UIElementcontent = this.targetImage asUIElement; Matrixmatrix = newMatrix(); MatrixTransformtransformMatrix = targetImage.RenderTransform asMatrixTransform; if(transformMatrix! = null)if(this.targetImage isFrameworkElement)FrameworkElementframeworkElement = this.targetImage asFrameworkElement; PointtransformCenter = this.TranslatePoint(e.ManipulationOrigin ,$ frameworkElement); newMatrixTransform(matrix); voidmanipulationProcessor_Affine2DManipulationCompleted(objectsender, Affine2DOperationCompletedEventArgse)#endregion #region { } { position.Y< 0 || position.X> targetImage.Width || position.Y> targetImage.Height) $ {UI事件HandlersprivatevoidtargetImage_PreviewContactDown(objectsender, ContactEventArgse)privatevoidtargetImage_PreviewContactChanged(objectsender, ContactEventArgse)if(!e.Contact。 IsFingerRecognized)return; Pointposition = e.Contact.GetPosition(this); if(position.X< 0 || // e.Contact.Capture(targetImage) ,$ System.Windows.Input.CaptureMode.None); e.Contact.Capture( downContacts.Remove(e。联系); $ } this,CaptureMode.None); if(downContacts.Contains(e.Contact))else {// e.Contact.Capture(targetImage, System.Windows.Input.CaptureMode.SubTree); e.Contact.Capture( $ manipulationProcessor.BeginTrack(e.Contact); e.Handled = downContacts.Add(e.Contact); } } {this, CaptureMode.SubTree); true; if(!downContacts.Contains(e.Contact))privatevoidtargetImage_PreviewContactUp( objectsender, $ ContactEventArgse)if(!e.Contact.IsFingerRecognized)return; // e.Contact.Capture(targetImage, ,System.Windows.Input.CaptureMode。无); e.Contact.Capture( downContacts.Remove(e.Contact); } this,CaptureMode.None );#endregion } } < s:SurfaceWindowx:Class =" teste2.SurfaceWindow1" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml " xmlns:s =" http://schemas.microsoft.com/surface/2008 " xmlns:l =" clr-namespace:teste2" Title =" teste2">< S:SurfaceWindow.Resources>< ImageBrushx:密钥= QUOT; WindowBa ckground"拉伸= QUOT;无"不透明度= QUOT; 0.6"的ImageSource = QUOT;包://应用:,,, /资源/ WindowBackground.jpg" />< /秒:SurfaceWindow.Resources>< GridBackground =" {StaticResourceWindowBackground}" Name =" tt" >< ViewboxName =" targetImage" Width =" 1024" Height =" 798" MinWidth =" 1024" MinHeight =" 798">< l:testcontrolWidth =" 1024 4 " Height =" 798" MinHeight =" 798" MinWidth = " 1024">< / l:testcontrol>< / Viewbox>< /< / Grid> s:SurfaceWindow> Iim using manipulation to scale my user control . And i want to know how toapply a minimun scale . I mean , i dont want to reduce my user control morethan my usercontrol min widht and min height.here is my application:xaml:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Shapes;usingSystem.Windows.Threading;usingMicrosoft.Surface;usingMicrosoft.Surface.Presentation;usingMicrosoft.Surface.Presentation.Controls;usingMicrosoft.Surface.Presentation.Manipulations;usingSystem.Windows.Interop;namespace{teste2///<summary>///Interaction logic forSurfaceWindow1.xaml///</summary>publicpartialclassSurfaceWindow1:SurfaceWindow{///<summary>///Default constructor.///</summary>///#region ClassMembersList<Contact>downContacts;doublelastExpansionDelta;Affine2DManipulationProcessormanipulationProcessor;Affine2DInertiaProcessorinertiaProcessor;#endregion#regionProperties#region{}ZoomSensitivity DPpublicdoubleZoomSensitivityget{return(double)GetValue(ZoomSensitivityProperty); }set{SetValue(ZoomSensitivityProperty, value); }// Using a DependencyProperty as thebacking store for ZoomSensitivity. This enables animation, styling, binding,etc...publicstaticreadonlyDependencyPropertyZoomSensitivityProperty=DependencyProperty.Register("ZoomSensitivity", typeof(double),typeof(SurfaceWindow1), newUIPropertyMetadata(6.0));#endregion#region{}PanSensitivity DPpublicdoublePanSensitivityget{return(double)GetValue(PanSensitivityProperty); }set{SetValue(PanSensitivityProperty, value); }// Using a DependencyProperty as thebacking store for PanSensitivity. This enables animation, styling, binding,etc...publicstaticreadonlyDependencyPropertyPanSensitivityProperty=DependencyProperty.Register("PanSensitivity", typeof(double),typeof(SurfaceWindow1), newUIPropertyMetadata(1.0));#endregion#region{}TiltSensitivity DPpublicdoubleTiltSensitivityget{return(double)GetValue(TiltSensitivityProperty); }set{SetValue(TiltSensitivityProperty, value); }// Using a DependencyProperty as thebacking store for PanSensitivity. This enables animation, styling, binding,etc...publicstaticreadonlyDependencyPropertyTiltSensitivityProperty=DependencyProperty.Register("TiltSensitivity", typeof(double),typeof(SurfaceWindow1), newUIPropertyMetadata(0.5));#endregion #endregion{InitializeComponent();lastExpansionDelta = 0;downContacts =targetImage.AddHandler(targetImage.AddHandler(targetImage.AddHandler(publicSurfaceWindow1()newList<Contact>();this.manipulationProcessor=newAffine2DManipulationProcessor(Affine2DManipulations.TranslateX|Affine2DManipulations.TranslateY|Affine2DManipulations.Scale,this, false);this.manipulationProcessor.Affine2DManipulationCompleted +=newEventHandler<Affine2DOperationCompletedEventArgs>(manipulationProcessor_Affine2DManipulationCompleted);this.manipulationProcessor.Affine2DManipulationDelta+=newEventHandler<Affine2DOperationDeltaEventArgs>(manipulationProcessor_Affine2DManipulationDelta);this.manipulationProcessor.Affine2DManipulationStarted+=newEventHandler<Affine2DOperationStartedEventArgs>(manipulationProcessor_Affine2DManipulationStarted);this.inertiaProcessor= newAffine2DInertiaProcessor();this.inertiaProcessor.Affine2DInertiaDelta +=newEventHandler<Affine2DOperationDeltaEventArgs>(inertiaProcessor_Affine2DInertiaDelta);this.inertiaProcessor.Affine2DInertiaCompleted+=newEventHandler<Affine2DOperationCompletedEventArgs>(inertiaProcessor_Affine2DInertiaCompleted);Contacts.PreviewContactDownEvent,newContactEventHandler(targetImage_PreviewContactDown));Contacts.PreviewContactChangedEvent,,newContactEventHandler(targetImage_PreviewContactChanged));Contacts.PreviewContactUpEvent,newContactEventHandler(targetImage_PreviewContactUp));// Add handlers forApplication activation eventsAddActivationHandlers();} ///<summary>///Occurs when the window is about to close. ///</summary>///<paramname="e"></param>{protectedoverridevoidOnClosed(EventArgse)base.OnClosed(e);//Remove handlers for Application activation eventsRemoveActivationHandlers();}///<summary>///Adds handlers for Application activationevents.///</summary>{privatevoidAddActivationHandlers()// Subscribe to surfaceapplication activation events}ApplicationLauncher.ApplicationActivated +=OnApplicationActivated;ApplicationLauncher.ApplicationPreviewed +=OnApplicationPreviewed;ApplicationLauncher.ApplicationDeactivated +=OnApplicationDeactivated;///<summary>///Removes handlers for Applicationactivation events.///</summary>{privatevoidRemoveActivationHandlers()//Unsubscribe from surface application activationevents}ApplicationLauncher.ApplicationActivated -=OnApplicationActivated;ApplicationLauncher.ApplicationPreviewed -=OnApplicationPreviewed;ApplicationLauncher.ApplicationDeactivated -=OnApplicationDeactivated;///<summary>///This is called when application has beenactivated.///</summary>///<param name="sender"></param>///<paramname="e"></param>{privatevoidOnApplicationActivated(objectsender,EventArgse)//TODO: enable audio, animations here}///<summary>///This is calledwhen application is in preview mode.///</summary>///<paramname="sender"></param>///<paramname="e"></param>{privatevoidOnApplicationPreviewed(objectsender,EventArgse)//TODO: Disable audio here if it is enabled//TODO: optionally enableanimations here}///<summary>///This is called when application has beendeactivated.///</summary>///<param name="sender"></param>///<paramname="e"></param>{privatevoidOnApplicationDeactivated(objectsender,EventArgse)//TODO: disable audio, animations here} #region{}{}{}{ProcessManipulationInertiaDelta(e);}Inertia Processor EventHandlersvoidinertiaProcessorZoom_Affine2DInertiaCompleted(objectsender,Affine2DOperationCompletedEventArgse)voidinertiaProcessorZoom_Affine2DInertiaDelta(objectsender,Affine2DOperationDeltaEventArgse)voidinertiaProcessor_Affine2DInertiaCompleted(objectsender,,Affine2DOperationCompletedEventArgse)voidinertiaProcessor_Affine2DInertiaDelta(objectsender,Affine2DOperationDeltaEventArgse)#endregion#region{inertiaProcessor.End();}{ProcessManipulationInertiaDelta(e);} {containerRect.Width = 1024;containerRect.Height = 798; {matrix = transformMatrix.Matrix;}matrix.Translate(-e.Delta.X, -e.Delta.Y); { transformCenter = matrix.Transform(transformCenter);matrix.RotateAt(e.RotationDelta, transformCenter.X, transformCenter.Y);matrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X,transformCenter.Y);} targetImage.RenderTransform = }{}Manipulation Processor EventHandlersvoidmanipulationProcessor_Affine2DManipulationStarted(objectsender,Affine2DOperationStartedEventArgse)voidmanipulationProcessor_Affine2DManipulationDelta(objectsender,Affine2DOperationDeltaEventArgse)privatevoidProcessManipulationInertiaDelta(Affine2DOperationDeltaEventArgse)RectcontainerRectt = newRect(this.RenderSize);UIElementcontent = this.targetImageasUIElement;Matrixmatrix = newMatrix();MatrixTransformtransformMatrix =targetImage.RenderTransform asMatrixTransform;if(transformMatrix !=null)if(this.targetImage isFrameworkElement)FrameworkElementframeworkElement =this.targetImage asFrameworkElement;PointtransformCenter =this.TranslatePoint(e.ManipulationOrigin,frameworkElement);newMatrixTransform(matrix);voidmanipulationProcessor_Affine2DManipulationCompleted(objectsender,Affine2DOperationCompletedEventArgse)#endregion#region{}{position.Y < 0 ||position.X > targetImage.Width ||position.Y > targetImage.Height){UI Event HandlersprivatevoidtargetImage_PreviewContactDown(objectsender,ContactEventArgse)privatevoidtargetImage_PreviewContactChanged(objectsender,ContactEventArgse)if(!e.Contact.IsFingerRecognized)return;Pointposition =e.Contact.GetPosition(this);if(position.X < 0 ||//e.Contact.Capture(targetImage,System.Windows.Input.CaptureMode.None);e.Contact.Capture( downContacts.Remove(e.Contact);}this, CaptureMode.None);if(downContacts.Contains(e.Contact))else{//e.Contact.Capture(targetImage,System.Windows.Input.CaptureMode.SubTree);e.Contact.Capture(manipulationProcessor.BeginTrack(e.Contact);e.Handled =downContacts.Add(e.Contact); }}{this,CaptureMode.SubTree); true;if(!downContacts.Contains(e.Contact))privatevoidtargetImage_PreviewContactUp(objectsender,ContactEventArgse)if(!e.Contact.IsFingerRecognized)return;//e.Contact.Capture(targetImage,, System.Windows.Input.CaptureMode.None);e.Contact.Capture(downContacts.Remove(e.Contact);} this, CaptureMode.None);#endregion }} <s:SurfaceWindowx:Class="teste2.SurfaceWindow1"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:s="http://schemas.microsoft.com/surface/2008"xmlns:l="clr-namespace:teste2"Title="teste2"><s:SurfaceWindow.Resources><ImageBrushx:Key="WindowBackground"Stretch="None"Opacity="0.6"ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/></s:SurfaceWindow.Resources><GridBackground="{StaticResourceWindowBackground}"Name="tt"><ViewboxName="targetImage"Width="1024"Height="798"MinWidth="1024"MinHeight="798"><l:testcontrolWidth="10244"Height="798"MinHeight="798"MinWidth="1024"></l:testcontrol></Viewbox></</Grid>s:SurfaceWindow>推荐答案 我显然没有编译你上面粘贴的代码,但是在ManipulationDelta事件处理程序上:如果你达到你的最小宽度就不要做任何事情/身高。I obviously did not compile the code you pasted above, but on the ManipulationDelta event handler: just don't do anything if you hit your min width / height.谢谢! -Luis Cabrera-Luis Cabrera 这篇关于定义最小规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-14 05:36