.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Zooming Canvas and ScrollBars !

Posted By:      Posted Date: October 26, 2010    Points: 0   Category :WPF

Hello Everyone,

I may be asking too many questions out here, but I have no other source.. so sorry for flooding the forum.


My question is:

I have a canvas, which I zoom in/out on mouse scroll:


            DockPanel myDockPanel = new DockPanel();
            myDockPanel.LastChildFill = true;

            //Add cnavas and the status bar to dock panel.

            this.elementHost.Child = myDockPanel;



            //Get the current matrix
            Matrix currentMattrix = this.canvas.LayoutTransform.Value;


View Complete Post

More Related Resource Links

Zooming in/out on canvas: how to leave some children unscaled?


I'm working with Visual Studio 2008 and I have created a window with a Canvas in a ScrollViewer. On the canvas, I've placed an image and the code I've written places buttons on the canvas at certain locations. So far, so good, but I'm trying to implement a zooming method which scales the canvas and the image, but leaves the buttons intact in terms of size and content -- however, their location should scale together with the image and the canvas.
What I have thusfar is this:

private void zoomIn(Object sender, MouseButtonEventArgs e)
  mapCanvas.Width *= ZoomFactor;
  mapCanvas.Height *= ZoomFactor;
  Zoom *= ZoomFactor;
  TransformGroup transform = new TransformGroup();
  transform.Children.Add(new ScaleTransform(Zoom, Zoom));
  transform.Children.Add(new TranslateTransform(0, 0));
  mapCanvas.RenderTransform = transform;

This, together with an analogue zoomOut method, works like a charm, but the buttons are scaled as well, obviously because RenderTransform is applied to every child of the canvas as well.

My question is: how can I leave the buttons unscaled?

How to customize workflow canvas in re-host environment?

Hi there,  Currently I'm developing a re-hosted debugger for Windows Workflow.  For the workflow canvas, I'm using View property of WorkflowDesigner class and bind my ContentControl to it.  The question here is, how to customize the WorkflowDesigner.View? Examples of customization are:   Extract the overview window, so that I can put the window in another part of the UI Change the zoom tool into the slide bar as in MS Word.   Thanks and best regards,  Arinto

Saving Canvas and other UIElements as embedded resource

Hi All, I am trying to save a canvas and its content as an embedded resource to another assembly but in doing so I got a Non-Serializable exception. Is there a better way of doing this? Here is the code I used in embedding the Canvas: // create an assembly AssemblyName assemblyName = new AssemblyName(System.IO.Path.GetFileNameWithoutExtension(filename)); AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll"); // create a class TypeBuilder typeBuilder = moduleBuilder.DefineType("ModuleName", TypeAttributes.Public, typeof(EmbeddedBAML)); // Create a default constructor ConstructorBuilder constuctorDefault = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes); ILGenerator ilGenerator = constuctorDefault.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Call, typeof(EmbeddedBAML).GetConstructor(Type.EmptyTypes)); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); IResourceWriter resourceWriter = assemblyBuilder.DefineResource(assemblyName.Name + ".canvas", "Contains the Canvas object",assemblyName.Name + ".canvas", ResourceAttributes.Pu

usercontrol layout in canvas at runtime puts in mult. copies of 1st element in collection.

I created a usercontrol which has a few DP's that match up with fields in a sql table. The requirements of this control specify if I get a specific status value I will flash the usercontrol to draw attention to a specific area of equipment in the facility. I also provide a tooltip which has all the fields of data to view. The usercontrol should only display it's description. On a button click I run the following code which instantiates a new observablecollection of my custom usercontrol (I call it profiNode). It then fills a dataset by calling our DAL and then I loop through the datarows using the values to create a new profiNode object for each row. I then add these to the observable collection, but I suppose a generic list would work too.     ProfiNodes = new ObservableCollection< profi.profiNode > (); DataSet data = new DataSet(); data = this.DataLayer.getDataSet("Select * from ProfibusMapping", CommandType.Text, null); foreach (DataRow row in data.Tables[0].Rows) { profi.profiNode node = new profi.profiNode((string)row.ItemArray[0],(int)row.ItemArray[1], (int)row.ItemArray[2], (int)row.ItemArray[3], (string)row.ItemArray[4], (DateTime)row.ItemArray[5], (int)row.ItemArray[6], (int)row.ItemArray[7], (string) row.ItemArray[8], (double)row.ItemArray[9], (double)row.ItemArray[10]); node.ID = string.Format("node_M{0}_A{1}&q

dynamically add scrollbars to datagrid

 I am creating multiple datagrids at runtime within a placeholder. I want to add scrollbars to them.Please can someone help me as i dont know how to add scrollbars to datagrids created at runtime.I am using .net 1.1

how to create property widget and change the properties of dragged-dropped UIelement in canvas in wp

I'm new in WPF development. I'd like to learn it. I'm curious and having problem in developing property widget for the UIElements. I want to change the properties of the dragged and dropped UIElement from the Property widget. How could I do this? I'd glad if any help is suggested. I've listbox and canvas. Elements from listbox can be dropped to the canvas. I'm trying to change the properties of the dropped element through a property widget. I don't know how to do this. I'd be grateful to any kind of support.   Regards, Binaya

different mouseWheel handlers for canvas and image

i have different mouse wheel handler for both canvas and image in that canvas,,but when i move my mouse over image and roll the wheel then the canvas mousewheel handler also starts working,,here is my code:   void img_MouseWheel(object sender, MouseWheelEventArgs e) { if (e.Delta > 1) { ((Image)sender).Width =((Image)sender).ActualWidth*1.01; ((Image)sender).Height = ((Image)sender).ActualHeight*1.01; } if (e.Delta < 1) { ((Image)sender).Width = ((Image)sender).ActualWidth/1.01; ((Image)sender).Height =((Image)sender).ActualHeight/1.01; } } <pre lang="x-c#">void mycanvas_MouseWheel(object sender, MouseWheelEventArgs e) { if (e.Delta > 1) { ((Canvas)sender).Width = ((Canvas)sender).ActualWidth*1.01; ((Canvas)sender).Height = ((Canvas)sender).ActualHeight*1.01; foreach(UIElement myElement in ((Canvas)sender).Children) { if (myElement is Image) { Image myimage = myElement as Image; myimage.Width *= 1.01 ; myimage.Height *= 1.01; } } } if (e.Delta < 1) { ((Canvas)sender).Width = ((Canvas)sender).ActualWidth /1.01; ((Canvas)sender).Height = ((Canvas)sender).ActualHeight/1.01; foreach (UIElement myElement in ((Canvas)sender).Children) { if (myElement is Image) { Image myimage = myElement as Imag

WebBrowser zooming in WPF

I am using a System.Windows.Controls.WebBrowser control in my WPF application to display an HTML page, but require the ability to zoom in/out of the page. I have found an option for windows forms: http://slingkid.blogsome.com/2007/04/13/ie-zoom/ , but I cannot see how/if this applies to the WPF WebBrowser control. Any help would be appreciated

Zooming image in Listview

I've read most of the posts but none with zooming in listview.I've created a photo album using listview in .net 3.5.I'm now interested in getting the pictures zoomed to the original size from the pinpoints  when onmouseover or onmouseclick actions are done.Thanks for the support.Martyn

Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc.,

Hello, I have a method that is passed in a FrameworkElement Ctrl.  When I use Ctrl.GetType().ToString() I get "System.Window.Controls.TextBox" or another string if a different type of control is passed in.  All I am interested in is the text after the last dot/period.  In my searching I thought I came across something that just returned the portion I'm looking for, but now can't find it. Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc., without its parents? Regards, Robert

zooming effect

hi!! i have a canvas on which there are number of images,,i want a zoom in/out effect currebtly on wheelmove event i increase/decrease the size of canvas and images is there any other way to do true zoom in/out ?? thanks

Maps report zooming

i have a pushpin map and have a requrement all my pushpins are appearing in only 1 state and that 1 state is dynamic we cannot hard code the state i want to zoom in to the location where i have all the pushpins

Items data binding in Canvas

Hello! I have an ObservableCollection, which contains points with X and Y coordinates. I need to bind this ObservableCollection to Canvas control, but there is no way to bind collection directly to Canvas. I found a few samples with ItemsControl (and ListBox). <Canvas x:Name="Root"> <ItemsControl ItemsSource="{Binding AllObjects}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.Left" Value="{Binding Longitude}" /> <Setter Property="Canvas.Top" Value="{Binding Latitude}" /> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate DataType="{x:Type o:OperationPoint}"> <Ellipse Width="3" Height="3" Fill="Blue" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Canvas> It works, but there are many elements in visual tree I don't need: Canvas (Root) ItemsControl Border ItemsPresenter Canvas ContentPresenter Ellipse ContentPresenter

Ink Canvas or Ink Presenter



I need to load the jpeg image into asp.net page and allow the users to draw some sketches on the image and save the image with the sketches. I am able to do it using WPF Ink Canvas in Windows application but I really not sure how can I achieve the same in ASP.NET web application. Please can anyone throw some ideas on this.




Disable horizontal and/or vertical scrollbars on ReportViewer Webpart


Hello everybody,

I have set up SSRS 2008 and SharePoint Foundation 2010 and try to build a website showing all kind of reports. But I do have problems to control the appearance of scrollbars in the webpart.

To make it easier to explain I created a report where all sizes (Page size, Interactive and Text body) have the similar size (width: 100mm and height: 50mm).

Next I made an empty Wiki Site with single column layout and inserted a Reportviewer Webpart based on the generated report. I set the height to 70mm and the width to 120mm.

Here is the result: http://img213.imageshack.us/img

How I can get coordinate textbox carete in Canvas.

Hi !
I have following xaml:

<UserControl x:Class="Dev1.Pronto.AD4.Modules.AdProcessing.Views.AdTextView"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Label Content="MyLabel"/>

Move all children on canvas or preferrably move the entire canvas



I´m working on a small app that parses the gpx file from the GPS. It will animate how me and my dog moves when we go hunting. I want to zoom in so that I can analyse how the dog is working and therefore need the graph to scroll and keep my position centered.

Yesterday I used a Canvas and plotted my points as black rectangles and the dog as red rectangles. Then used the SetLeft and SetTop to scroll the Canvas. I then added a polyline connecting the dogs points but didnt find StLeft and SetTop for the polyline. Played around with RenderTransform but never got it working.

1. My question is is canvas suitable for this?

2. Is there a way to move the entire canvas and all its children in one command?

3. Is there a generic way that can be used to move all UIElements.

By move I mean move relative an element relative to its current position, for example 2 pixels left and 5 pixels up.



Trying to learn
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend