|
|
Browse by Tags
All Tags » WPF samples » Programming (RSS)
-
Viewport2DVisual3D .... this new feature makes things a lot easier in the 3D world.. What this enables is putting interactive 2D on 3D. This makes things like having a textbox in 3D a breeze... < Viewport2DVisual3D x:Name = " vp2d_multiple_children " Geometry = " {StaticResource mesh} " > < Viewport2DVisual3D.Material > < DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial = " True " Brush = " White " /> </ Viewport2DVisual3D.Material > <TextBox /> </ Viewport2DVisual3D > One other thing is mapping 3D points to 2D is so much more easier... Earlier on I had a post on mapping a mouseclick on a 3d model to a 2d coordinate. This involved using some barycentric coordinates and such... Now all you need is call e.GetPosition(relativeTo) in the mouse event handler... tada!!... your coordinates are ready... so using this new stuff i created a simple app for keeping track of your travels. right clicking on the globe puts a tag on the globe. Clicking on the Read More...
|
-
In 3.0, we received a number of queries regarding creating plugins. So in 3.5 we got this in .. :) .. Creating an adding would bsically need the use of 3 dlls - System.Addin, System.Addin.Contract, System.Presentation The basic steps to create the addins involves creating a contract, then create the corresponding views and adapsters for both the host and the addin. So in total you will be creating 5 dlls in addition to the app and the actual addin. Even though this looks a bit overwhelming, its pretty simple. http://blogs.msdn.com/clraddins/ gives more information about creating addins. In order to try out this framework, I added the addin support to blogpad with the host being able to set text in the addins... So the app basically has an addin for a calculator (which can be removed) and an ad at the side... You can try out the code that is attached .. FYI, the ad plugin links to an xbap and this line is commented in code.. You might want to point it to a legit xbap to get this plugin working. Read More...
|
-
Pavan has a nice post on creating baloon comments. The first thing that comes to mind on seeing the balloon comments is Comics. And guess what! thats exactly what I tried.. and presto You can get the original source code here . It overlooks positioning the arrows coming out of the comment boxes - this is a minor detail and I added a dependency property for this purpose. The update code is attached . As for the usage: < custom:BalloonDecorator Background = "Pink " PointerLength = " 30 " CornerRadius = " 5 " CornerPosition = " Right" .... /> Share this post Read More...
|
-
Recently, I was trying my hand at creating a simple blog writer. The writer came out pretty nice. The app makes use of a base richEditor control (thanks to Praj ).. After a bit of tweaking it ended up like the above... So the app just makes a simple call in the xaml <custom:RichEditor/> ...tada ... you have it there!!! The next thing is to write to a blog... In this case, the writer is coded to post the entry on blogger, which makes use of the Google data API .. this could easily be changed for other blogs. It also makes use of a Xaml-HTML converter as the string passed needs to be in HTML. For now, its a blog writer - hence, it onluy writes. But it could easily be extended into a full blown Blog client. Do I hear anyone taking it up :) The code is attached .. so have fun with it .. Share this post Read More...
|
-
just came across a post which includes xaml to display the xaml shield. That looks sweet.. and all the more when its in Xaml... Xaml code attached Share this post Read More...
|
-
If you have tried creating FileDialogs in WPF, they usually do not blend well into the Vista look. The solution is to use the wrappers provided in the VistaBridge library which is part of the SDK samples. You could include the library dll (around 100k) in your project and then make the simple call to CommonOpenFileDialog/CommonSaveFileDialog ... The other option being to just include the specific classes in the project. CommonSaveFileDialog saveDialog = new CommonSaveFileDialog (); Its that easy!! Share this post Read More...
|
-
Feng Yuan has a nice blog post on how to convert FlowDocuments to an XPS document with the header. The code is in the form of a wrapper class so its gonna be handy. I tried out the code on a RichTextBox and it worked like a charm J I reused one of my old samples and it looks great :) ... The sample code is attached . (PS: Do make a point a read the original post for code specific details) Share this post Read More...
|
-
Recently I was clearing up my documents and I came across this sample I made. Thought it might be useful to someone out there and here it is. It’s basically something like a form but which dynamically grows as and when you fill up the rows. So the typical ‘Add New Row’ button is missing. J … Red (more like pink) rows indicate values being empty; green being obvious. :) .. Typically, you would be using a combobox instead of the textbox. It would result in a better perf experience. The code is simple using a listview which is bound to the data. This might look very familiar to Product Studio if you have used it ;) Code is attached Share this post Read More...
|
-
Recently I was trying my hand at a rough image editing scenario and one of the things was changing into gray scale, brightness and so forth. If you have played with .NET 2.0 you get quite a few functions which help in these types of operations and it would be nice shifting Images to Bitmaps and vice versa. As luck would have it, Robert had posted some code on this in the forums. To get the Bitmap you would have to call CopyPixels on the BitmapSource and convert it to a Bitmap- transformedBitmapSource.CopyPixels(bits, stride, 0); unsafe { fixed ( byte * pBits = bits) { IntPtr ptr = new IntPtr (pBits); System.Drawing. Bitmap bitmap = new System.Drawing. Bitmap ( width,height,stride, System.Drawing.Imaging. PixelFormat .Format32bppPArgb,ptr); return bitmap; } } To do the reverse: System.Windows.Media.Imaging. BitmapSource bitmapSource = System.Windows.Interop. Imaging .CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr .Zero, Int32Rect .Empty, System.Windows.Media.Imaging. BitmapSizeOptions Read More...
|
-
Dependency property is a pretty kewl concept. You got to agree on that J . One the nice features is the ability to listen to the changes in these properties and I tend to use it a lot. The SDK way would be to derive from the control, override the dependencyproperty metadata and specify the propertychangedCallback in the signature. Hmmm… pretty cumbersome you would say. public class MyTextBox : TextBox { public MyTextBox(): base () { } static MyTextBox() { FlowDirectionProperty.OverrideMetadata( typeof ( MyTextBox ), new FrameworkPropertyMetadata ( new PropertyChangedCallback (FlowDirectionPropertyChanged))); } private static void FlowDirectionPropertyChanged( DependencyObject sender, DependencyPropertyChangedEventArgs args) { (( MyTextBox )sender).FontWeight = ((( MyTextBox )sender).FlowDirection == FlowDirection .RightToLeft) ? FontWeights .Bold : FontWeights .Normal; } } But hey, things get easy, thanks to Ben . What you can do is use the DependencyPropertyDescriptor. DependencyPropertyDescriptor Read More...
|
-
Some time back I got a question about capturing the contents of a frame and it seemed easy, but every time I tried capturing the frame i was getting a blank image. The trick here is that the frame loads the content asynchronously - the simplest thing to do is wait for some time :) ... The frame is an HwndHost that hosts an ActiveX control to load the web content. So the first thing to do is get hold of the HwndHost and then wait for a few seconds and you have it.. for ( Visual v = TheFrame; v != null ; v = VisualTreeHelper .GetChild(v, 0) as Visual ) { hwndHost = v as HwndHost ; if (hwndHost != null ) { break ; } } Now create a DispatcherTimer and wait till it triggers DispatcherTimer timer = new DispatcherTimer (); timer.Tick += TheFrameAfterLoaded; timer.Interval = TimeSpan .FromSeconds(5); timer.Tag = hwndHost; timer.Start(); void TheFrameAfterLoaded( object sender, EventArgs e) { DispatcherTimer timer = sender as DispatcherTimer ; HwndHost hwndHost = ( HwndHost ) timer.Tag; timer.Stop(); Read More...
|
-
Often times when I go through the WPF forums, I see people getting confused with WPF and WPF/E..... (don’t miss the ‘E’).. One of things that is on many of our minds is ‘why not xbap’. Chad summarizes the difference in his blog pretty well. “ WPF/E Applications · Are cross-platform ready (Mac OS X and Windows) · Do not require the client to have the .NET 3.0 runtime. Instead, WPF/E applications run within a browser plugin. · Do not support code-behind · Rely on JavaScript XBAPs · Require the client to have the .NET 3.0 runtime components installed. · Are not cross-platform enabled. They will only run on Windows machines. · Support code-behind · Must run within IE (or use the IETab plugin for Firefox)” I decided to get my hands dirty with WPF/E and its pretty simple. What you really need to get going is: · WPF/E SDK · WPF/E template for VS (comes with the SDK but needs to be installed) · Expression Blend is nice to have. No 3D support yet but you can get effects like the above pretty easily. Read More...
|
-
This sounds simple but its not so since we do not make it public. So what are the options we have here. hmmm... How about an hack J . The caret color is the inverse of the background color. So a very simple way is to set the background which then doesn’t get rendered. <Style TargetType="{x:Type TextBox}"> <Setter Property="KeyboardNavigation.TabNavigation" Value="None" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="AllowDrop" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Grid> <Border x:Name="Border” BorderThickness="2" SnapsToDevicePixels="True" Padding="2" CornerRadius="2"> <ScrollViewer Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleTextScrollViewer}" /> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="{DynamicResource Read More...
|
-
Recently, Praj blogged about printing content of a RichTextBox. Normally, if you use the documentPaginator or the visual, you might end up with some text clipped. Not a nice thing to happen J . One thing that bugs me while printing is the print dialog. Often times, I just want to use a printer that’s not busy. Just don’t make me wait. It’s pretty simple to code and its worth it. No more waiting at the printer. ;)
foreach ( PrintQueue pq in GetPrintQueues( "\\\\servername" )) { if (!pq.IsBusy) { Print(pq); return ; } } private IEnumerable < PrintQueue > GetPrintQueues( string servername) { PrintServer ps; if ( string .IsNullOrEmpty(servername)) { // local printer name ps = new LocalPrintServer (); } else { // network printer share ps = new PrintServer (servername); } return ps.GetPrintQueues(); } void Print( PrintQueue pq) { TextRange sourceDocument = new TextRange (richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); MemoryStream stream = new MemoryStream Read More...
|
-
A ScrollViewer is a very handy control. One of the problems, however, is bringing a control to Focus or scrolling to the item. If this is done manually, that’s not an issue. But programmatically hmm.. You can hit some issues. The simplest way is to call the scrollviewer’s ScrollToVerticalOffset() with the offset being the Y co-ordinate. But what if the element is partially visible and you do not want it to scroll. This would require determining if the element is in the ScrollViewers viewport. The way to achieve this is simple. Suppose ContainedObject is the element inside the Scrollviewer (ScrollViewerObj) // position of your visual inside the scrollviewer GeneralTransform childTransform = ContainedObject .TransformToAncestor( ScrollViewerObj ); Rect rectangle = childTransform.TransformBounds( new Point (0,0), ContainedObject .RenderSize); //Check if the elements Rect intersects with that of the scrollviewer's Rect result = Rect .Intersect( new Rect ( new Point (0, 0), ScrollViewerObj .RenderSize),rectangle); Read More...
|
|
|
|