tag:blogger.com,1999:blog-54888014378537655892024-03-05T06:33:31.595-08:00WPF and C#SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-5488801437853765589.post-52461204750414170252010-11-15T10:46:00.000-08:002010-11-15T10:52:45.934-08:00Cannot convert the value in attribute 'Property' to object of type 'System.Windows.DependencyProperty'. isloaded<link type="text/css" rel="stylesheet"
<br />
<br />href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript"
<br />
<br />src="js/shCore.js"></script>
<br /><script language="javascript"
<br />
<br />src="js/shBrushCSharp.js"></script>
<br /><script language="javascript"
<br />
<br />src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf =
<br />
<br />'/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br />
<br />This problem is typically encountered when you are trying to use IsLoaded like a dependency property
<br />
<br />e.g
<br />
<br /><pre name="code" class="xml">
<br /> <Trigger Property="IsLoaded" Value="True">
<br /> <Trigger.EnterActions>
<br /> <BeginStoryboard>
<br /> <Storyboard AutoReverse="True" >
<br /> <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="glowImage" To="1" BeginTime="0:0:0" Duration="0:0:1" />
<br /> <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="glowImage" To="0" BeginTime="0:0:1" Duration="0:0:2" />
<br /> </Storyboard>
<br /> </BeginStoryboard>
<br /> </Trigger.EnterActions>
<br />
<br /></pre>
<br />Its wierd at the first look why IsVisible a dependency property and not IsLoaded.SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-59436988717522719222009-05-16T11:47:00.001-07:002009-05-16T11:49:58.665-07:00Hello World using Composite application guidance and Visual studio 2008 templates.<object width="400" height="300"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4680875&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1"><embed src="http://vimeo.com/moogaloop.swf?clip_id=4680875&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><p><a href="http://vimeo.com/4680875">Hello World using WPF, Composite application guidance and VS 2008 templates.</a> from <a href="http://vimeo.com/user1648469">Pradeep Mahdevu</a> on <a href="http://vimeo.com/">Vimeo</a>.</p><p><br /></p><p>For further details about visual studio 2008 templates for prism/Composite application guidance read this <a href="http://pradeepmahdevu.blogspot.com/2009/04/vs-2008-templates-for-composite.html">linky</a><br /></p>SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-22843571018888924672009-05-11T18:46:00.000-07:002009-05-11T18:50:49.481-07:00Resharper 4.5 is kicka$$ :)There is a newer release of Resharper, version 4.5 available. If you haven’t put your hands on it, I suggest you do. I could see a lot of improvements compared to the previous versions (especially performance). All licenses purchased after Dec 21, 2007 qualify for a free upgrade to ver. 4.5. According to their website these are some of the new developments.<br /><br /><br /><br />§ Performance and memory consumption: When working on large solutions, you’ll feel a great deal of difference between ReSharper 4.0 and 4.5.<br /><br />§ New solution-wide warnings and suggestions: Analyze usage of non-private types and type members within your whole solution.<br /><br />§ Visual Basic 9 support: ReSharper’s cross-language refactorings and editing experience enhancements now provide support for VB9 code.<br /><br />§ Extended setup for naming conventions, which are now supported by all ReSharper features.<br /><br />§ New Inline Field refactoring and enhancements in existing refactorings.<br /><br />§ Go to Implementation: Go from usage of a class or method straight to its end implementation, bypassing abstract classes and/or interfaces.<br /><br />If you would like to see a quick demo of all the features, here they <a href="https://rnomail.igt.com/OWA/redir.aspx?C=84a2602509b34a1b89d4adb7ba14aa4f&URL=http%3a%2f%2fwww.jetbrains.com%2fresharper%2fdocumentation%2fpresentation%2frs45%2fwhatsnew-rs45.html">are</a>... If you like it and would like to download the new 4.5 release follow this <a href="https://rnomail.igt.com/OWA/redir.aspx?C=84a2602509b34a1b89d4adb7ba14aa4f&URL=http%3a%2f%2fwww.jetbrains.com%2fresharper%2fdownload%2fdownload_thanks.jsp%3fos%3drs">linky</a>. Here is the <a href="https://rnomail.igt.com/OWA/redir.aspx?C=84a2602509b34a1b89d4adb7ba14aa4f&URL=http%3a%2f%2fwww.jetbrains.com%2fresharper%2fdocs%2fReSharper45FeatureMap.pdf">4.5 feature map</a>.<br /><br />If you are updating your Resharper.. Please copy your user name and license key on a notepad as a backup.<br />Happy Coding,<br /><br />PradeepSPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-40151598150206889842009-04-23T14:18:00.000-07:002009-05-16T11:53:53.079-07:00VS 2008 Templates for Composite Application Guidance (Prism v2)<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css">
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript"><br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';<br />dp.SyntaxHighlighter.HighlightAll('code');<br /></script>
<br />
<br />Most of the credit for this post goes truly to <a href="http://blogs.msdn.com/knom/archive/2008/10/22/visual-studio-templates-composite-wpf-guidance-installation.aspx">Knom </a>who created the initial versions of Visual studio templates. I have been using them for a while, though I always felt that it is broken or incomplete, so here is the newer version.
<br />
<br /><span style="font-weight: bold;">RELEASE NOTES</span>
<br />
<br />The revisions in this modification are
<br />a) The new version works only with February 2009 Composite Application Guidance. It refers to the IModuleCatalog introduced in this release.
<br />b)The references like Microsoft.Practices.composite broken in the previous release are fixed now!
<br />c) The new dlls like Microsoft.Practices.composite.presentation.dll are referred instead of Microsoft.Practices.composite.wpf.dll
<br />d) Namespaces in view and presentation models are fixed in this release.
<br />e) every module can have its own name and the same with ModuleController.
<br />f) Unnecessary imports have been removed.
<br />g) Slicker interface.
<br />
<br />
<br />If you like this, please goto knom's page and contribute. I dont need any! (may be a comment if it is useful to you !) You can completely write a Prism application in less than ten minutes using this application.
<br />
<br /><span style="font-weight: bold;">INSTALLATION NOTES</span>
<br />
<br />a) If you have not installed Composite Application Guidance, install it <a href="http://msdn.microsoft.com/en-us/library/dd458809.aspx">here</a>.
<br />
<br />b) Download the Visual studio templates for composite application Binaries <a href="http://pradeep.chandra.googlepages.com/Prism_VisualStudio2008Bin.zip">here</a>.
<br />
<br />c) Unzip this and you will find three files.
<br /> * install.bat does all the work to setup the templates (run the .VSI and add the .DLL to the global assembly cache)
<br /> * CompositeTemplateWizards.dll contains the Wizards used from the project templates. This assembly must be installed into the GAC.
<br /> * Templates.vsi is VSI installer package with all the templates (need the wizard assembly in the GAC).
<br />
<br />
<br />d) Run the install.bat
<br />
<br />
<br />
<br />
<br /><span style="font-weight: bold;">Upgrade</span>
<br />If you are upgrading from knoms templates then just follow the same instructions and when installing, it would ask you for a over ride. Do override the old files!
<br />
<br />
<br />
<br /><span style="font-weight: bold;">Trouble shooting Notes</span>
<br />a) If you have more than two versions of Visual studio you might not be able to see these templates when you click "new project". In that case
<br />
<br />Goto Programs> Microsoft VS 2008> Visual studio tools \ Visual studio 2008 command prompt
<br />
<br />In here change your directory to the base directory where you have the install, run the following command.
<br />
<br />
<br /><span style="font-weight: bold;">gacutil.exe -i CompositeTemplateWizards.dll</span>
<br />
<br />Restart vs 2008 and things should start working
<br />
<br />
<br />
<br />
<br />
<br />b) After installing the "composite application guidance 2.0" Visual studio 2008 templates, as a one time activity create a libraries folder with following libraries.
<br />
<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-9m_77jpUnzXZxGTuvxYbETJJZLeYk5zUXfjHa24UHMMtKVepy1cERxFdJe_TqCe0zeo7G8Hv_b9x3JLrkUFYH4XgUmVk4KVxJ_jWtr10XPLOmnYguL6IYuDRTYHUbL-PF57TgrDiga13/s1600-h/Installation1.png"><img style="cursor: pointer; width: 320px; height: 143px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-9m_77jpUnzXZxGTuvxYbETJJZLeYk5zUXfjHa24UHMMtKVepy1cERxFdJe_TqCe0zeo7G8Hv_b9x3JLrkUFYH4XgUmVk4KVxJ_jWtr10XPLOmnYguL6IYuDRTYHUbL-PF57TgrDiga13/s320/Installation1.png" alt="" id="BLOGGER_PHOTO_ID_5328003587687347106" border="0" /></a>
<br />
<br />This folder will be useful in creating the Prism apps.
<br />
<br />
<br />
<br />SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-55543596833558532302009-04-14T17:38:00.000-07:002009-04-14T21:12:14.860-07:00Running animations in MVVMWe implement Composite application guidance (Prism v2) in our application. Recently we wanted to run animations when something changes in ViewModel. The Viewmodel changes should initiate storyboards or run functions on view.xaml code behind. <br /><br />I implemented a class ViewModelChangeDispatcher which can be useful to run animations.<br />You can instantiate this lightweight class from xaml as<br /><br /><pre name="code" class="xml" ><br /><br /><inf:ViewModelChangeDispatcher Source="{Binding xxxxxAnimation}"<br />OnSourceChangedStartStoryboard="XXXStoryBoard" /><br /></pre><br />The above VMCD is bound to Source xxxAnimation, this when changed will automatically call the storyboard... <br /><br />If you want to manage multiple animations using the same, u can handle that by this code<br /><pre name="code" class="xml" ><br /><br /><inf:ViewModelChangeDispatcher Source="{Binding XXXXAnimation}" SourceChanged="RunAnimation"/><br /><br /><br /></pre><br /><br />When source is changed the event handler RunAnimation is called. <br /><br />Anyway here is how I implemented ViewModelChangeDispatcher.<br /><pre name="code" class="c-sharp"><br /><br />public class ViewModelChangeDispatcher : FrameworkElement<br />{<br />#region Data<br /><br />public static readonly DependencyProperty SourceProperty;<br />public static readonly DependencyProperty OnSourceChangedStartStoryboardProperty;<br /><br />// The routed event<br />public static RoutedEvent SourceChangedEvent;<br /><br />#endregion // Data<br /><br />#region Static Constructor and static methods<br /><br /><br />static ViewModelChangeDispatcher()<br />{<br />SourceProperty = DependencyProperty.Register(<br />"Source",<br />typeof(String),<br />typeof(ViewModelChangeDispatcher),<br />new FrameworkPropertyMetadata(string.Empty,OnSourcePropertyChanged));<br /><br /><br /><br />OnSourceChangedStartStoryboardProperty = DependencyProperty.Register(<br />"OnSourceChangedStartStoryboard",<br />typeof(Storyboard),<br />typeof(ViewModelChangeDispatcher));<br /><br /><br />//Registering the events<br />SourceChangedEvent = EventManager.RegisterRoutedEvent("SourceChanged",<br />RoutingStrategy.Bubble,<br />typeof(RoutedEventHandler),<br />typeof(ViewModelChangeDispatcher));<br /><br />}<br /><br />private static void OnSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)<br />{<br /><br />ViewModelChangeDispatcher vmcd = d as ViewModelChangeDispatcher;<br />if (vmcd == null) return;<br /><br />vmcd.RaiseEvent(new RoutedEventArgs(SourceChangedEvent, vmcd));<br />if (vmcd.OnSourceChangedStartStoryboard == null) return;<br />vmcd.OnSourceChangedStartStoryboard.Begin();<br />}<br /><br /><br /><br />#endregion<br /><br />#region constructor and members<br />public ViewModelChangeDispatcher()<br />{<br />this.Visibility = Visibility.Collapsed;<br />this.Width = 0;<br />this.Height = 0;<br /><br /><br />}<br /><br />/*<br />* Source is always string.<br />* It is the onus of the markupextension to convert it to a string.<br />*<br />* */<br />public String Source<br />{<br />get { return (String)GetValue(SourceProperty); }<br />set { SetValue(SourceProperty, value); }<br />}<br /><br /><br /><br />public event RoutedEventHandler SourceChanged<br />{<br />add { AddHandler(SourceChangedEvent, value); }<br />remove { RemoveHandler(SourceChangedEvent, value); }<br />}<br /><br />public Storyboard OnSourceChangedStartStoryboard<br />{<br />get { return (Storyboard)GetValue(OnSourceChangedStartStoryboardProperty); }<br />set { SetValue(OnSourceChangedStartStoryboardProperty, value); }<br />}<br />#endregion<br /><br /><br />}<br /><br /><br /></pre><br /><br />Please let me know if you have any comments/inputs!<br /><br />Happy coding!<br />Pradeep Mahdevu<br /><br />www.pradeepmahdevu.blogspot.com<br /><br /><br />Also refer <a href="http://www.thejoyofcode.com/Animating_when_data_changes.aspx">Josh Twist's point of view on this.<br />joy of code</a> and pavan's post here...<br /><br /><a href="http://blog.pixelingene.com/">Pixel in genie</a>SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com10tag:blogger.com,1999:blog-5488801437853765589.post-55957195227784829752009-04-14T10:19:00.000-07:002009-04-14T17:33:12.820-07:00Composite application Guidance Prism Logging<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br />Coming from a Java web development world, I always love the ease of use of apache commons logging, I recently implemented logging in our WPF application based on <a href="http://msdn.microsoft.com/en-us/magazine/cc785479.aspx">Composite Application guidance</a> (CAL or Prism v2). We use the Microsoft way of logging, <a href="http://msdn.microsoft.com/en-us/library/cc467894.aspx">Enterprise Library</a> 4.1. Though the performance is sluggish compared to log4net, we wanted to use this for various other reasons.
<br />
<br />This blog entry would help you set up you CAL with enterprise logging. I created a class called CustomLogger. CustomLogger encapsulates Logger. You can either resolve ICustumLogger or ILoggerFacade to use this. ICustomLogger provides interface common to Apache commons logging and ILoggerFacade provides interface common to Enterprise Logging.
<br />
<br />First looking at registering the ILoggerFacade. The BootStrapper overrides LoggerFacade to return the customLogger.
<br /><pre name="code" class="c-sharp">
<br /> internal class Bootstrapper : UnityBootstrapper
<br /> {
<br /> // CustomLogger is a custom logger implementation.
<br /> CustomLogger logger= new CustomLogger();
<br />
<br />
<br /> protected override ILoggerFacade LoggerFacade
<br /> {
<br /> get
<br /> {
<br /> return logger;
<br /> }
<br /> }
<br />
<br /> protected override void ConfigureContainer()
<br /> {
<br /> Container.RegisterType<ICustomLogger, CustomLogger>(new ContainerControlledLifetimeManager());
<br />
<br /> base.ConfigureContainer();
<br /> }
<br />
<br /> }
<br /></pre>
<br />We register two things with the container, the ILoggerFacade and the ICustomLogger. Though there is a mere small additional cost,the benefit of this is huge, ILoggerFacade is used by the CAL to log things in trace.log and ICutomLogger is used by app to log things.
<br />
<br />An example of logging using this interface is ...
<br />
<br />
<br />
<br /><pre name="code" class="c-sharp">
<br /> public XXXXXXXXXPresentationModel(IUnityContainer container,
<br /> IMagCardInfoView view,
<br /> IEventAggregator eventAggregator,
<br /> ICustomLogger logger,
<br /> IMagCardCommandsView commandsView,
<br /> IRegionManager regionManager)
<br /> : base(eventAggregator)
<br /> {
<br /> logger.Debug("New XXXXXX Presentation model requested.");
<br />
<br /> }
<br /></pre>
<br />
<br />The ICustomLogger interface looks like
<br />
<br /><pre name="code" class="c-sharp">
<br />
<br /> public interface ICustomLogger
<br /> {
<br />
<br /> void Info(string message);
<br />
<br />
<br /> void Debug(string message);
<br />
<br />
<br /> void Warn(string message);
<br />
<br />
<br />
<br /> void Exception(string message);
<br />
<br /> }
<br /></pre>
<br />
<br />The CustomLogger looks like
<br /><pre name="code" class="c-sharp">
<br /> public class CustomLogger: ICustomLogger, ILoggerFacade
<br /> {
<br />
<br /> public void Info(string message)
<br /> {
<br /> Logger.Write(message, Category.Info.ToString(), (int)Priority.High);
<br /> }
<br />
<br />
<br /> public void Debug(string message)
<br /> {
<br /> Logger.Write(message, Category.Debug.ToString(), (int)Priority.High);
<br /> }
<br />
<br />
<br /> public void Warn(string message)
<br /> {
<br /> Logger.Write(message, Category.Warn.ToString(), (int)Priority.High);
<br /> }
<br />
<br />
<br /> public void Exception(string message)
<br /> {
<br /> Logger.Write(message, Category.Exception.ToString(), (int)Priority.High);
<br /> }
<br />
<br />
<br /> #region ILoggerFacade Members
<br />
<br /> public void Log(string message, Category category, Priority priority)
<br /> {
<br /> Logger.Write(message, category.ToString(), (int)priority);
<br /> }
<br />
<br /> #endregion
<br /> }
<br /></pre>
<br />
<br />SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com1tag:blogger.com,1999:blog-5488801437853765589.post-16469508661992593012009-04-13T14:05:00.000-07:002009-04-14T18:56:00.221-07:00WPF UI Waiting for server animated with dependency control.<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br />
<br />Writing a WPF application often requires communicating with Server. When the WPF application requires to contact with server, we would like to show a neat animation on the UI like Internet explorer.
<br />
<br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/DZ8C27nKVrI&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/DZ8C27nKVrI&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
<br />
<br />
<br />
<br />
<br />This listing shows a way to create an userControl which can be used in applications like
<br />
<br /><pre name="code" class="xml">
<br /><Window
<br />.....
<br /> xmlns:WA="clr-namespace:WaitingAnimated" .... />
<br />
<br /> <WA:FrontEndWaiting Width="25" Height="25" x:Name="animatedIcon"
<br /> Margin="200, 50, 300, 300"/>
<br /></pre>
<br />
<br />In the source code attached I have a toggle button which starts/stops the animation by setting the value of IsAnimated to true or false...
<br />
<br /><pre name="code" class="c-sharp">
<br />private void Button_Click(object sender, RoutedEventArgs e)
<br /> {
<br />
<br /> animatedIcon.IsAnimated = !animatedIcon.IsAnimated;
<br /> }
<br />
<br /></pre>
<br />Going thru XAML in the user control which is not rocket science but still...
<br />
<br />The Grid.Resources has a storyboard, the repeat behavior of animation is forever and the storyboard target property is Angle of the path.
<br /><pre name="code" class="xml">
<br /> <Grid.Resources>
<br /> <Storyboard x:Key="OnLoaded">
<br /> <DoubleAnimationUsingKeyFrames
<br /> BeginTime="00:00:00"
<br /> Storyboard.Target="{Binding ElementName=path}"
<br /> Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"
<br /> RepeatBehavior="Forever">
<br /> <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="360"/>
<br /> </DoubleAnimationUsingKeyFrames>
<br /> </Storyboard>
<br /> </Grid.Resources>
<br /></pre>
<br />
<br />Path is the union of two circles. The important things in path are the rendertransform origin which translates the origin to the corresponding value, i typically define rendertransform and add all children even if i dont use to keep code extensible. Path fill is the color in the circular path which is filled .
<br /><pre name="code" class="xml">
<br /><Path Stretch="Fill" Stroke="#7F505050"
<br /> Data="........"
<br /> RenderTransformOrigin="0.5,0.5" x:Name="path">
<br /> <Path.RenderTransform>
<br /> <TransformGroup>
<br /> <ScaleTransform ScaleX="1" ScaleY="1"/>
<br /> <SkewTransform AngleX="0" AngleY="0"/>
<br /> <RotateTransform Angle="0"/>
<br /> <TranslateTransform X="0" Y="0"/>
<br /> </TransformGroup>
<br /> </Path.RenderTransform>
<br /> <Path.Fill>
<br /> <LinearGradientBrush EndPoint="50,100" StartPoint="50,0" SpreadMethod="Pad" MappingMode="Absolute">
<br /> <GradientStop Color="#E500FF00" Offset="0"/>
<br /> <GradientStop Color="#3F2BBF2B" Offset="1"/>
<br /> <GradientStop Color="#9B020C02" Offset="0.32"/>
<br /> <GradientStop Color="#FFFFFFFF" Offset="0.641"/>
<br /> </LinearGradientBrush>
<br /> </Path.Fill>
<br /> </Path>
<br />
<br /></pre>
<br />
<br />Source code <a href="http://pradeep.chandra.googlepages.com/WaitingAnimated.zip">here</a>.
<br />SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-91538768285132790482009-02-06T08:32:00.000-08:002009-04-14T18:49:21.745-07:00Flying Grids using margin animation<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/fLw5QcESnkk&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fLw5QcESnkk&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
<br />
<br />The idea of doing this is to make the application comfortable for left handed and right handed people equally. We came across this problem when we started development of app for touchscreens. The RH people required the command grid on RHS and LH ppl on left handed respectively. There are two grids, One is a command grid (referred as commGrid) and the other is mainGrid. The mainGrid has a button Swap me! When the button is hit, the main grid and commGrid swap. the main window of the app (window1.xaml) has following grid ( superGrid).
<br /><pre name="code" class="xml">
<br /> <Grid x:Name="superGrid">
<br /> <Grid.RowDefinitions>
<br /> <RowDefinition></RowDefinition>
<br /> </Grid.RowDefinitions>
<br /> <Grid.ColumnDefinitions>
<br /> <ColumnDefinition Width="0.8*"></ColumnDefinition>
<br /> <ColumnDefinition Width="0.2*"></ColumnDefinition>
<br /> </Grid.ColumnDefinitions>
<br /> <Grid x:Name="mainGrid" Grid.Column="0" Margin="0,0,0,0" Panel.ZIndex="1">
<br /> <Border BorderThickness="5" CornerRadius="20" BorderBrush="Black"/>
<br /> <Button Click="Button_Click" Width="100" Height="100">Swap me!</Button>
<br /> </Grid>
<br /> <Grid x:Name="commGrid" Grid.Column="1" Margin="0,0,0,0" Panel.ZIndex="99">
<br /> <Border BorderThickness="5" CornerRadius="20" BorderBrush="Black"/>
<br /> </Grid>
<br /> </Grid>
<br /></pre>
<br />
<br />The button_click event handler is as follows...
<br />
<br /><pre name="code" class="c-sharp">
<br /> private void Button_Click(object sender, RoutedEventArgs e)
<br /> {
<br /> //calculate commGrid and mainGrid widths
<br /> double commGridWidth = commGrid.ActualWidth;
<br /> double mainGridWidth = mainGrid.ActualWidth;
<br />
<br /> //animated is a bool const at app level to check if animation is enabled.
<br /> if(animated)
<br /> AnimateGrids(changeDexter, commGridWidth, mainGridWidth);
<br /> else
<br /> {
<br /> GridChange(commGridWidth, mainGridWidth);
<br /> changeDexter(this, EventArgs.Empty);
<br />
<br /> }
<br />
<br />
<br /> }
<br /></pre>
<br />The most important function where the central logic lies is AnimateGrids. Since Margin does not have a animation by itself, we can use thickness animation. I have two animations, one for each grid.
<br />
<br /><pre name="code" class="c-sharp">
<br /> private void AnimateGrids(EventHandler postAnimation, double commGridWidth, double mainGridWidth)
<br /> {
<br />
<br />
<br />
<br />
<br /> /*
<br /> * If commGrid is right
<br /> * commGrid.Margin.Left should move from 0 to -mainGridWidth
<br /> * commGrid.Margin.Right should move from 0 to +mainGridWidth
<br /> *
<br /> * If commGrid is left
<br /> * commGrid.Margin.Left should move from 0 to +mainGridWidth
<br /> * commGrid.Margin.Right should move from 0 to -mainGridWidth
<br /> *
<br /> */
<br />
<br />
<br />
<br /> Storyboard sb = new Storyboard();
<br />
<br /> ThicknessAnimation commGridAnimation
<br /> = new ThicknessAnimation
<br /> {
<br /> From =
<br /> new Thickness(0),
<br /> To =
<br /> new Thickness((isRightHanded ? -1 : 1) * mainGridWidth, 0,
<br /> (isRightHanded ? 1 : -1) * mainGridWidth, 0),
<br /> AccelerationRatio = 0.2,
<br /> FillBehavior = FillBehavior.Stop,
<br /> DecelerationRatio = 0.8,
<br /> Duration = DURATION
<br /> };
<br />
<br /> ThicknessAnimation mainGridAnimation
<br /> = new ThicknessAnimation
<br /> {
<br /> From =
<br /> new Thickness(0),
<br /> To =
<br /> new Thickness((isRightHanded ? 1 : -1)*commGridWidth, 0,
<br /> (isRightHanded ? -1 : 1)*commGridWidth, 0),
<br />
<br /> FillBehavior = FillBehavior.Stop,
<br /> AccelerationRatio = 0.2,
<br /> DecelerationRatio = 0.8,
<br /> Duration=DURATION
<br />
<br /> };
<br />
<br />
<br /> Storyboard.SetTarget(commGridAnimation, commGrid);
<br /> Storyboard.SetTargetProperty(commGridAnimation,
<br /> new PropertyPath(MarginProperty));
<br />
<br /> Storyboard.SetTarget(mainGridAnimation, mainGrid);
<br /> Storyboard.SetTargetProperty(mainGridAnimation,
<br /> new PropertyPath(MarginProperty));
<br />
<br />
<br />
<br /> sb.Children.Add(commGridAnimation);
<br /> sb.Children.Add(mainGridAnimation);
<br />
<br /> sb.Completed += new EventHandler(postAnimation);
<br />
<br /> sb.Begin();
<br />
<br />
<br />
<br /> }
<br />
<br />
<br /></pre>
<br />
<br />ChangeDexter is an event handler which is defined as
<br /><pre name="code" class="c-sharp">
<br /> private void changeDexter(object sender, EventArgs e)
<br /> {
<br /> isRightHanded = !isRightHanded;
<br /> //Swap columns
<br /> Grid.SetColumn(mainGrid, isRightHanded ? 0 : 1);
<br /> Grid.SetColumn(commGrid, isRightHanded ? 1 : 0);
<br />
<br /> //Swap widths
<br /> GridLength gl = superGrid.ColumnDefinitions.ElementAt(0).Width;
<br /> superGrid.ColumnDefinitions.ElementAt(0).Width = superGrid.ColumnDefinitions.ElementAt(1).Width;
<br /> superGrid.ColumnDefinitions.ElementAt(1).Width = gl;
<br />
<br />
<br />
<br /> }
<br /></pre>
<br />ChangeDexter is called at the end of animation.
<br />
<br />
<br />
<br />Download source code <a href="http://pradeep.chandra.googlepages.com/MovingGrids.zip">here</a>
<br />
<br />
<br />Happy coding!
<br />Pradeep MahdevuSPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com2tag:blogger.com,1999:blog-5488801437853765589.post-6025869633292135812008-12-26T11:48:00.000-08:002008-12-26T13:07:57.595-08:00Test to use code highlighting<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br />In future i want to use syntax highlighter for my code postings on this blog... i hope this works
<br />
<br /><pre name="code" class="xml">
<br /><Grid.RowDefinitions>
<br /> <RowDefinition Height="*" />
<br /> <RowDefinition Height="10" />
<br /> </Grid.RowDefinitions>
<br /> <Grid.ColumnDefinitions>
<br /> <ColumnDefinition Width="*" />
<br /> <ColumnDefinition Width="10" />
<br /> </Grid.ColumnDefinitions>
<br /></pre>SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-80736824903602699622008-11-07T14:14:00.001-08:002008-11-07T14:23:50.386-08:00ClickOnce Application architecture for multiple customers<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWA0F20vugRmfytrKgXl5ll5ZcYZrxdIU2rv4zeTlgn1ZgCLxBq7Obp-n8Mzn3arxwgBBAr9ocTDJsnUj4UbU9OcyFaTxyif3liCts5Cct33wZlk0JzQEO9uWDNC19zhS1QjctuvAuZIzO/s1600-h/MultipleCustomers.JPG"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 174px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWA0F20vugRmfytrKgXl5ll5ZcYZrxdIU2rv4zeTlgn1ZgCLxBq7Obp-n8Mzn3arxwgBBAr9ocTDJsnUj4UbU9OcyFaTxyif3liCts5Cct33wZlk0JzQEO9uWDNC19zhS1QjctuvAuZIzO/s320/MultipleCustomers.JPG" alt="" id="BLOGGER_PHOTO_ID_5266044897165764162" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVtlBZVENbmzdIcVjto7xA9uqiCQrhVu7dessppkg756Atc4tWi-iwHepKon_FIUGNed0pnplnm4R6dTN5qZ2cmn87S9_skScPGRnT68SlC2wVoYt-zAhKrpNd6Z_oAH1pGsoPXCgwtWie/s1600-h/DEVenv.JPG"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 298px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVtlBZVENbmzdIcVjto7xA9uqiCQrhVu7dessppkg756Atc4tWi-iwHepKon_FIUGNed0pnplnm4R6dTN5qZ2cmn87S9_skScPGRnT68SlC2wVoYt-zAhKrpNd6Z_oAH1pGsoPXCgwtWie/s320/DEVenv.JPG" alt="" id="BLOGGER_PHOTO_ID_5266044161904339522" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDBZH5nye14iJisnAG_KcY3-OsXUfE5GabhkFBKwUrVtwZOERLnrUsH6GbtVr3I9XfspNLDaNPDjuHOgSvaS5FMyMZ_ld2zze8mfLbXmSFU88j5LHU1jasJQo0aNX3yQ3I-Obva4xJGflU/s1600-h/ClickOnce.JPG"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 205px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDBZH5nye14iJisnAG_KcY3-OsXUfE5GabhkFBKwUrVtwZOERLnrUsH6GbtVr3I9XfspNLDaNPDjuHOgSvaS5FMyMZ_ld2zze8mfLbXmSFU88j5LHU1jasJQo0aNX3yQ3I-Obva4xJGflU/s320/ClickOnce.JPG" alt="" id="BLOGGER_PHOTO_ID_5266044155529248290" border="0" /></a>SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0tag:blogger.com,1999:blog-5488801437853765589.post-53959212952204577822008-11-05T10:25:00.000-08:002009-04-15T11:28:15.448-07:00XBAP and Serial Port<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHEZCHfHvSSRjNGkzMEyktvqAJv52g6x6L6ZjpTStQz2oJEb9020Pm-HRGEhxpK02tH8V98qGzPj6FByjNj4_FC8XKVdGKamvG2ixhJiWfFj2QgI1taAqMA_0HgUf2mU7rtnqy5oU2OSrZ/s1600-h/Picture+2009-04-15+11_24_03.jpg"><img style="cursor:pointer; cursor:hand;width: 320px; height: 142px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHEZCHfHvSSRjNGkzMEyktvqAJv52g6x6L6ZjpTStQz2oJEb9020Pm-HRGEhxpK02tH8V98qGzPj6FByjNj4_FC8XKVdGKamvG2ixhJiWfFj2QgI1taAqMA_0HgUf2mU7rtnqy5oU2OSrZ/s320/Picture+2009-04-15+11_24_03.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5324986087990408258" /></a>
<br /><link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<br /><script language="javascript" src="js/shCore.js"></script>
<br /><script language="javascript" src="js/shBrushCSharp.js"></script>
<br /><script language="javascript" src="js/shBrushXml.js"></script>
<br /><script language="javascript">
<br />dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
<br />dp.SyntaxHighlighter.HighlightAll('code');
<br /></script>
<br />
<br />XBAP (XAML Browser Application) is a new Windows technology used for creating Rich Internet Applications. While windows applications are normally compiled to an .exe file, browser applications are compiled to an extension .xbap and can be run inside Internet Explorer.
<br />
<br />Xbap applications are run within a security sandbox to prevent untrusted applications from controlling local system resources. (e.g deleting local files)
<br />
<br />But If your application requires peripherals access, the user can run an xbap in full trust mode. <a href="http://blogs.microsoft.co.il/blogs/maxim/archive/2008/03/31/how-to-run-wpf-xbap-application-in-full-trust-mode-post-2-certificate-extraction.aspx">Here </a>is how you can set up a XBAP application in full trust mode.
<br />
<br />
<br />
<br />Here in this application, the main page just has a Button. When clicked, the eventhandler opens the COM3 port and flushes data.
<br />
<br />The following code prints a ticket on the COM3 port.
<br /><pre name="code" class="c-sharp">
<br /> public void button_click(object sender, RoutedEventArgs e)
<br /> {
<br /> try
<br /> {
<br />
<br /> System.Text.Encoding enc = System.Text.Encoding.ASCII;
<br /> System.Console.WriteLine("Hello world");
<br />
<br />
<br /> // Instantiate the communications // port with some basic settings
<br /> SerialPort port = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
<br />
<br /> // Open the port for communications
<br />
<br /> ReadFromFile("c:\\Cash_Out_Ticket_Test_Stock_424_200_data.txt", port);
<br />
<br />
<br /> }
<br /> catch (System.UnauthorizedAccessException)
<br /> {
<br /> System.Console.WriteLine("Com port occupied. Please choose another port");
<br />
<br /> }
<br /> }
<br /></pre>
<br />
<br />Source code <a href="http://pradeep.chandra.googlepages.com/XBAPPortAccessTest.zip">here</a>.
<br />
<br />Happy coding!
<br />Pradeep Mahdevu
<br />
<br />http://pradeepmahdevu.blogspot.com
<br />SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com2tag:blogger.com,1999:blog-5488801437853765589.post-52772939255856531502008-11-05T10:17:00.000-08:002008-11-05T10:38:26.356-08:00XAML Power Toys<div class="post_item_text"> <h3 style="font-family: arial; font-weight: normal; color: rgb(0, 0, 0);" class="post_title"><span style="font-size:85%;">The XAML Power toys are a great help to increase your productivity in day to day development. You can download powertoys <a href="http://karlshifflett.wordpress.com/xaml-power-toys/">here</a>.<br /></span></h3><h3 style="font-family: arial; font-weight: normal; color: rgb(0, 0, 0);" class="post_title"><span style="font-size:85%;">Here are some videos where you can see the power of this tool.</span></h3><h3 class="post_title"><a href="http://windowsclient.net/learn/video.aspx?v=77658">XAML Power Toys: Create Business Form</a></h3> <p class="post_description">This feature provides developers the necessary tool to layout a Grid, with controls and labels. Use this feature if you are creating a Grid that is not bound to a business entity object...</p> </div> <div class="post_item"> <div class="post_item_image"> <a href="http://windowsclient.net/learn/video.aspx?v=77659"><img src="http://windowsclient.net/Themes/leanandgreen/images/newui/icon_video.png" alt="Video" /></a> </div> <div class="post_item_text"> <h3 class="post_title"><a href="http://windowsclient.net/learn/video.aspx?v=77659">XAML Power Toys: Build Form For Class</a></h3> <p class="post_description">This feature puts the WPF & Silverlight form developer on steroids. This video covers selecting a class and creating a fully bound form effortlessly. When combined with well defined...</p> </div> </div> <div class="post_item_image"> <a href="http://windowsclient.net/learn/video.aspx?v=77660"><img src="http://windowsclient.net/Themes/leanandgreen/images/newui/icon_video.png" alt="Video" /></a> </div> <div class="post_item_text"> <h3 class="post_title"><a href="http://windowsclient.net/learn/video.aspx?v=77660">XAML Power Toys: Installation and Setup</a></h3> <p class="post_description">This is a must view video for all first time users of XAML Power Toys. This video covers installing and configuring security in Visual Studio 2008. Author: Karl Shifflett</p><p class="post_description"><br /></p><p class="post_description">~Pradeep Mahdevu</p><p class="post_description">http://pradeepmahdevu.blogspot.com</p><p class="post_description"><br /></p><p class="post_description"><br /></p> </div>SPoThttp://www.blogger.com/profile/15092796772925627907noreply@blogger.com0