Is it possible to update camera position and lookdirection without using XAML? - c#

I've got a WPF UserControl Library in Windows forms and I'm trying to update my camera position and lookdirection when event is triggered, but I want to do it without XAML. Is that even possible?
I have tried with:
userControl.Dispatcher.Invoke(()=>
{
userControl.UpdateCameraPOV();
});
But it's not working.

For doing any 3D work with .NET, the Helix Toolkit is a great help. It includes a view control woth pan/tilt movement, and might be a good start for a view that you can control via code too.

Related

WPF Bing Maps control: mouse scroll stops working after setting properties

Before setting zoomLevel or center property I can use my mouse to move around the map(dragging) and zoom in/out using scroll wheel. After setting one of those, mouse scroll zoom in/out stops working. I tried to register my own mousewheelevent handler and it too stops working togather with built-in one. I also tried this:
myMap.Center = center;
myMap.ZoomLevel = zoomLevel;
myMap.MouseWheel += new MouseWheelEventHandler(Map_MouseWheel);
But it didn't work. What's the problem here?
edit: tried also using
myMap.SetView(center,zoomLevel);
edit2: I'm using Integration.ElementHost to load WPF control in WinForms project. It gotta be something with that since with regular WPF project everything works fine.
You have to set focus to the map control
myMap.Focus()

Moving Control over a ScrollViewer

I'm developing a small WPF application which uses a ScrollViewer to show an Image in a Window.
I have generated the window and all his relative code (I will show it if needed but I think is not usefull for the point of this question) programmatically.
The question/ how to is the following. I have to show/hide (pressing a button) a control (basically a InkCanvas) over the image contained in the ScrollViewer. Except the part oh show/hide is pretty simple to use the button event) which is the best way to add a control (and which type of control/container) at the Window forcing him to be over the ScrollViewer and then be able to move around dragging it?
I'm relatively new to WPF I used a lot of WinForms (I can do this in WinForms but WPF is a new world for me).
Thanks in advance!
As for the container you should use a Grid which will center and put on top of each other the controls in a same cell.
As for drag and drop if you want to implement it yourself I've provided a minimal implementation here: https://stackoverflow.com/a/17014906/145757
Otherwise you can use the MouseDragElementBehavior behavior provided by Blend.
Here is a tutorial that demonstrates its usage from Blend itself: http://www.c-sharpcorner.com/uploadfile/nipuntomar/expression-blend-4-behaviors/
But you can use it without Blend by importing the Blend libraries and using it from your XAML with something like:
<InkCanvas ...>
<interactivity:Interaction.Behaviors>
<blendbehaviors:MouseDragElementBehavior />
</interactivity:Interaction.Behaviors>
</InkCanvas>
with interactivity and blendbehaviors being mapped to the Blend namespaces.

Create Animated Button

I have button it possible create animate on click?
with photoshop i have created a two image (enabled and disabled). Insert the picturebox in Windows Forms and Click event..Click the image changes from enabled to disabled, but you can have an animation?
Like this:
It looks like you mentioned WinForms so I'll address that. Yes animation is possible but in general it's going to be a bit of work.
There appears to be an implementation of a general purpose animation framework (although limited) over on CodeProject. In the comments schallos posted a better implementation of the reflection code using expression trees.
The general principle is:
Use a PictureBox so you get double buffering
Use a timer control to control repainting (calling Invalidate() on your PictureBox)
You'll probably want to add some easing into the animation so it appears smoother; a bit of acceleration added to it when the user clicks goes a long way.
A timer is not required using a GIF.
Using windows forms you could start by creating an animated GIF for each button. It would have to include both the forward and backwards direction. You can do this through Photoshop via the "Animation" panel. On the PictureBox click event you can set the image to play or stop.
The code below would set your image on the beginning frame.
imgButtonDimension = new FrameDimension(imgButtonDimension.FrameDimensionsList[0]);
imgButton.SelectActiveFrame(imgButtonDimension, 0);
pictureBox.Image = imgButton;`
If this is the approach you'd like to take I can provide further elaboration.

Adding anchor line to a Bing Maps custom pushpin and allowing the user to drag

I am currently working on a Silverlight application using the Bing Map control, i am using a custom pushpin made up of an Image and a text block within a grid element, which works fine, this also allows me to have hover and right click events for each pushpin so all good so far, however there is a need for me to enable the user to drag the pushpin in any direction and have an a line connecting it to its actual position, sort of like an anchoring point.
I am struggling to see how to do this, I have seen lots of information on making the pushpins have the capability to be moved by the mouse but the line and anchor part is causing me a bit of a problem. Currently i keep my pushpins in various Observable Collections so that when they are updated the UI updates. If anyone has an Idea on a clean way of adding this functionality please let me know it will be much appreciated.
Many Thanks
I haven't got time to knock up a complete example. However I'll give away the basis of the solution. Replace the template with one based on a Canvas. For example you could have an ellipse to be the actual point on the map, a draggable border that has the ContentPresenter and a line to act as a tether.
The code needed is a) allow the Border to be dragged about and b) to move one end of the line about so that it lies under the Border.
I am still interested in other approaches but I have come up with a solution of paring my pushpin element with a MapPolyline, this in conjunction with the mouse handling to allow the user to drag the pushpin updates both, it is pretty effective and will do for now. I would still like to hear from anyone else with better suggestions though.

C# slider control but - music studio style

I'm about to implement a slider control component in .NET that's along the lines of a music recording control.
With the timebased equalizer graph, and with the abilities of a regular slider. How to go about this?
Thanks guys - I wasn't very explanatory in my question -- I did find this which I very much like - http://www.codeproject.com/KB/progress/MediaSlider.aspx -- I'll customize it to my needs.
Try the Track Bar Control from DevExpress
http://www.devexpress.com/Products/NET/Controls/WinForms/Editors/editors/TrackBarControl.xml

Categories