Lester's WPF\SL Blog


Simple, Easy & Beautiful


 

Blog - Post Feedback Form(CAPTCHA)
  • Lester's WPF\Silverlight Blog

    WPF 3.5 SP1 feature: StringFormat

    • 20 Comments
    One of the new features in 3.5 SP1 is stringformat. The usage is pretty simple. So following are simple snippets showing its use < TextBox Text = " {Binding Path=Double, StringFormat=F3 } " /> < TextBox Text = " {Binding Path=Double, StringFormat=Amount: {0:C}} " /> < TextBox Text = " {Binding Path=Double, StringFormat=Amount: \{0:C\}} " /> < TextBox > < TextBox.Text > < Binding Path = " Double " StringFormat = " {}{0:C} " /> </ TextBox.Text > </ TextBox > < TextBox > < TextBox.Text > < MultiBinding StringFormat = " {}{0:F2} = {1:D} " > < Binding Path = " Double " /> < Binding Path = " Date " /> </ MultiBinding >...
  • Lester's WPF\Silverlight Blog

    XamlPadX 4.0

    • 21 Comments
    So I finally got a chance to update XamlpadX and heres the new version. Whats new. The UI has been revamped to give the Blend sorta look. Menus have been rearranged to maximize the space. New addins: Clipboard viewer - which works well for analyzing rtf/xaml ... Path Designer/Jasema (thanks to Marlon) Snapshot utility to take snapshots and save the xaml rendering Syntax highlighting and collapsing (thanks to the editor control from SharpDevelop project) Error logs - left bottom corner has a link to the stack trace when there is an error Error light - editor has a red/green box at the bottom right corner Bug fixes/code restructuring Also, i would like to point...
  • Lester's WPF\Silverlight Blog

    Maximizing window (with WindowStyle=None) considering Taskbar

    • 4 Comments
    Sainuu ... for people wondering what that is - its HI in Mongolian.. So here I am in Mongolia on my vacation and its going great... My blog will be neglected by me for the next couple of weeks..:) Ok now back to WPF.. One interesting problem that comes to mind is the Window occupying all screen space on Maximizing when the WindowStyle is set to None. So this means that even if we do have the taskbar visible the window would appear on top of that. This would not happen in the case of the normal window with the TitleBar. To get this scenario working, we would have to include a small piece of code ( by Josh Zana ) in the Window. public override void OnApplyTemplate() { System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;...
  • Lester's WPF\Silverlight Blog

    Listening to DependencyProperty changes

    • 8 Comments
    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...
  • Lester's WPF\Silverlight Blog

    XamlPadX v2

    • 22 Comments
    Season's greetings guys :) Hope your Christmas was great. Ok so before we go into the next year I thought I'll take a look at XamlPadX since it will get a bit tough to spend some time on it in the next year. So XamlpadX v2 looks like: New features: 1> Line numbers in the Editing box 2> Written xaml can now be indented automatically(Ctrl I or right click and click on the menu item) 3> Closing tags are automatically generated (Note that it doesnt look forward while generating the closing tag. This is to keep it as simple as possible) So if you have something like <A </A> and then type in the '>' after the first A you will end up with <A></A></A>. 4> Theres an Open/Save File menu for opening/saving...
  • Lester's WPF\Silverlight Blog

    BitmapSource-Bitmap interop

    • 3 Comments
    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...
  • Lester's WPF\Silverlight Blog

    Split Button in WPF

    • 5 Comments
    Split Button in WPF...
  • Lester's WPF\Silverlight Blog

    WPF WebBrowser (.NET 3.5 SP1)

    • 15 Comments
    One of the new controls is the WebBrowser... aha!! not the Winforms control.. we now have it in WPF. Functions supported by this control are: NavigateToString NavigateToStream Navigate GoBack GoForward In xaml it would look like something like this: < StackPanel Name = " panel " > < WebBrowser Height = " 500 " > </ WebBrowser > </ StackPanel > I put together a simple sample which tries to use this functionality Looks like the above. Nothing fancy :) Also since this is beta you might find a few rough edges (bugs) here and there.Please report them on the connect website or on the forums. Project Code: Attached Share this post
  • Lester's WPF\Silverlight Blog

    Date Picker/ Calendar controls now available

    • 3 Comments
    The date picker/ calendar control is now available at the WPF website. The controls were initially part of WPF but were removed for various reasons. However, it was promised that these controls would be made publicly available as a sample and its now public :)...yoohoo!! http://wpf.netfx3.com/files/folders/controls/entry5875.aspx UPDATE: these controls are now part of .NET 4. You can download the beta1 version (as of 7/23/09) Its also available in the WPF Toolkit on codeplex ( http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117 ). This code was released prior to be being included in 4.0. If you have 4.0, you dont need to use this dll.
  • Lester's WPF\Silverlight Blog

    Code for getting screen relative Position in WPF

    • 1 Comments
    One of the common customer queries that we see on the forums is to get the screen relative position of a point. Currently we do not provide an API which allows this functionality. However, Nick Kramer came up with this code on the forum and it works great for LTR (left to right) systems. Following is the code for getting the screen relative position : static Point TransformToScreen( Point point, Visual relativeTo) { HwndSource hwndSource = PresentationSource .FromVisual(relativeTo) as HwndSource ; Visual root = hwndSource.RootVisual; // Translate the point from the visual to the root. GeneralTransform transformToRoot = relativeTo.TransformToAncestor(root); Point pointRoot = transformToRoot.Transform(point); // Transform the point from the root...
  • Lester's WPF\Silverlight Blog

    XamlPadX (extended)

    • 14 Comments
    XamlPad Xtended ...
  • Lester's WPF\Silverlight Blog

    Drag drop library updated

    • 13 Comments
    The drag drop entry that I had posted has been used by a lot of you guys out there and I have received a lot of suggestions/bugs. I also got a few ready made fixes from you... Thank You :) ... So I finally got down to incorporating all these changes and got the new library up ... One frequent problem was the adorner flickering and this was a result of the adorner being deleted and created ... so thats fixed. There are also some fixes, code moving around and the usual stuff. Hope you find the new library useful :) Library attached Share this post
  • Lester's WPF\Silverlight Blog

    Vista look on Non-Aero themes

    • 10 Comments
    Vista look on Non-Aero themes...
  • Lester's WPF\Silverlight Blog

    Drag drop library

    • 4 Comments
    Some time back Marcelo had written a series of posts covering drag and drop. This was interesting reading and I had uploaded the C# code in one of my previous posts. Recently, I came across Pavans blog where he shows the same using attached properties. The code is written with reusability and ease of use in mind. To use the code you would need to specify the source and the destination (putting it in layman terms) < local:CanvasDragDropAdvisor x:Key = " advisor " /> < Canvas Background = " White " local:DragDropManager.DragSourceAdvisor = " {StaticResource advisor} " local:DragDropManager.DropTargetAdvisor = " {StaticResource advisor} " > You would need to implement the SourceAdvisor and TargetAdvisor ( in the above...
  • Lester's WPF\Silverlight Blog

    XamlPadX V3.0

    • 15 Comments
    So I finally got some time to upgrade XamlPadX... One of the things that I really wanted to add was the plugin support and here you have it. So now users can create their own addins which will plug into xamlpadX. Addin developers can use 3 functionalities of XamlPadX: void ChangeAppBackground( String str); String textBoxContents { get ; set ; } //this is the content in the xaml textbox int TextBoxCaretIndex //this is the caret index in the xaml textbox The color pallette is now included as an addin - so on installation we already have one plugin ready. All selected addins are included in the menu. To create a new addin, all you need is to create a control which extends AddInAddInView shown below ColorPallette : AddInViews. AddInAddInView...
  • Lester's WPF\Silverlight Blog

    Changing caret color in (Rich)TextBox

    • 0 Comments
    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...
  • Lester's WPF\Silverlight Blog

    Creating a timer

    • 1 Comments
    Lets move aways from the RSS readers... I hear some guys heaving a sigh of relief... hehe!! So lets start off with a timer which doesnt work as we usually expect it to..it works backwards!! Isnt that what we all wish. Anyway coming to the point, lets have a timer which counts down and on reaching ZERO plays a song. Sounds like a good app to wake you up when you plan to go for a short nap. The design is simple. We have a grid with the hour/min/secs and buttons for Starting and Reseting. There is a TextBox at the bottom which gives some status messages. :) The code looks like this in XAML: Window1.xaml <Window x:Class="timer.Window1" xmlns= http://schemas.microsoft.com/winfx/avalon/2005 xmlns:x= http://schemas.microsoft.com/winfx/xaml...
  • Lester's WPF\Silverlight Blog

    Arithmetic operations in Xaml

    • 4 Comments
    Arithmetic operations in Xaml...
  • Lester's WPF\Silverlight Blog

    Scrolling Scrollviewer on Mouse Drag at the boundaries

    • 1 Comments
    If you have used the scrollviewer control then one thing that you might have noticed is that the viewer doesnt scroll if we drag some data towards the boundary of the control. It would be nice if we could get the viewer to scroll on mouse drag. Try the following Xaml code - type in several lines of text so that the viewer scrolls. Now drag some text to the boundary - oops!! no scrolling .. <ScrollViewer xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Height="200"> <TextBox AcceptsReturn='True' VerticalScrollBarVisibility='Visible'>text</TextBox> </ScrollViewer > Dont sweat it :), Dan Crevier came up with some code which addresses the above. The...
  • Lester's WPF\Silverlight Blog

    Testing using WPF UI automation

    • 4 Comments
    One question that often pops up among WPF app developers is UI testing... WPF enables this scenario through a new accessibility framework. Some useful resources from mdeavey's post Overview Using UI Automation UI Spy Stress Test using UI Automation (new link : here ) Unit Testing WPF controls with Automation Peers Instantiating a WPF control from an NUnit test Adding UI Automation support to a custom control .NET UI Automation Extension for Automation Testing Share this post
Page 1 of 13 (241 items) 12345»