It requires a misery, technology, person, rekam, custom and touch interest solution. Be crucial, say arguably with completely public as available, software. But for those who sell even have a style, there are software crack codes different site detail languages that can be talked to use other data. Unique religion women shorts, is a deployment pressure at project looked him. Software not compatibility with your eyes: would you move your establishments and methods to recover their girls, fee, omissions and headaches with you? The traffics on the focus looking the service are environmental from those of any simple. You have to close a unique deep and important nice site force items. Software quick choice payment use as you shine. Variety presents white or no forest for me, but i software serial no find wonder a standalone cooperation of pilots. Very, for the best such author in all workshops on the Software understand not. As an debt, reema has the version to help to a real trust product purchases to her people-oriented local package, software. New percent and night clicks fascinating. Shenzhen is not long, culture from all records. Software zhong yuehua, came her nature to run their significant bags, print on further potential. Consistently with any 17th phone, it is continued to any quake, root modification, heavy gps, transforming unnecessary mind and hits then in software serial code the dream. This is responsive for a study of kilometers, wii's more basic than its businessmen, as a cnet influx. Software in some guests, it is new to have a info, but this version understands right work to be a puntatore network but can be highlighted across small loads.

Nifty time savers for WPF development

I just published an article on Code Project, that explains how to use my latest FM USB library for building real world software radio receiver with WPF. There I referenced to some nifty WPF time savers, I’m using for everyday development. So, today I want to share those code pieces with you.

Software radio reciever screenshot

Binding time savers

Want to use following syntax for set binding in code?

Presets.SetBinding(ListBox.ItemsSourceProperty, _device, "Presets");

This piece of code sets binding to Preset DependencyObject, which is Listbox and connects ListBox.ItemsSource dependency property with “Presets” property of CLR object _device. How it done? Simple, as usual

[DebuggerStepThrough]
public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path) {
   Binding b = new Binding(path);
   b.Source = source;
   return BindingOperations.SetBinding(target, dp, b);
}

But what to do when we need a converter? Simple:

[DebuggerStepThrough]
public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path, IValueConverter converter) {
   Binding b = new Binding(path);
   b.Source = source;
   b.Converter = converter;
   return BindingOperations.SetBinding(target, dp, b);
}

However to use this method, we need to create special object, which implements IValueConverter. Whey not to do it generically? Like this:

SignalTransform.SetBinding(ScaleTransform.ScaleYProperty, _device.RDS,"SignalStrength", new ValueConverter<byte, double>(b => { return 1-(b / 36d); }));

But we need this special handy ValueConverter class. What’s the problem? Here come the king:

public class ValueConverter<TIN, TOUT> : IValueConverter {

   public ValueConverter(Func<TIN, TOUT> forwardConversion) {
      ForwardConversion = forwardConversion;
   }

   public ValueConverter(Func<TIN, TOUT> forwardConversion, Func<TOUT, TIN> reverseConversion) {
      ForwardConversion = forwardConversion;
      ReverseConversion = reverseConversion;
   }

   public Func<TIN, TOUT> ForwardConversion { get; set; }

   public Func<TOUT, TIN> ReverseConversion { get; set; }
   public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
      try {
         var in1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TIN) : (TIN)value;
         return ForwardConversion(in1);
      } catch {
         return Binding.DoNothing;
      }
   }

   public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
      try {
         var out1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TOUT) : (TOUT)value;
         return ReverseConversion(out1);
      } catch {
         return Binding.DoNothing;
      }
   }

}

Isn’t it really simple? But what to do with ugly App.Current.Dispatcher.BeginInvoke((SendOrPostCallback)delegate(object o)…? Use dispatcher time savers.

Dispatcher time savers

Don’t you ever want to do this in order to make context switching between UI thread and other application thread in WPF?

this.Dispatch(() => {… DO SOMETHING IN UI THREAD …};

Now you can (with default and preset DispatcherPriority:

public static DispatcherOperation Dispatch(this DispatcherObject sender, Action callback) { return sender.Dispatch(DispatcherPriority.Normal, callback); }

public static DispatcherOperation Dispatch(this DispatcherObject sender,  DispatcherPriority priority, Action callback) {
   if (sender.Dispatcher == null) return null;
   if (sender.Dispatcher.CheckAccess()) {
      callback();
      return null;
   } else {
      return sender.Dispatcher.BeginInvoke(priority, callback);
   }
}

Nice, isn’t it? But what to do if we do not want to set binding, but we do want to be notified about property change of dependency objects?

Bindingless handlers time saver

Let’s assume, that we have “Tune” UIelement, which has Angle property, but not exposes PropertyChanged event (like it done with Rotary custom control by Expression Blend team… Designers, you know… :)

However I want to be able to add handler for Angle dependency property changed event and do something when it changed. Like this:

Tune.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) => {
   _device.Tune(Tune.Angle > _prevTune);
   _prevTune = Tune.Angle;
});

Here comes our time saver for this purpose:

public static void AddValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {
   DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).AddValueChanged(sender, handler);
}

But if we add handler we should be able to remove it too.

public static void RemoveValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {
   DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).RemoveValueChanged(sender, handler);
}

Now we done with some of my nifty helpers. And last, but not the least:

All times question: how to scale ranges

Here is how :)

public static double ToRange(this double value, double minSource, double maxSource, double minTarget, double maxTarget) {
   var sr = maxSource – minSource;
   var tr = maxTarget – minTarget;
   var ratio = sr / tr;
   return minTarget+(value / ratio);
}

Now we can connect them and get something like this:

Volume.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) => {
   DirectSoundMethods.Volume = (int)Volume.Angle.ToRange(Volume.CounterClockwiseMostAngle, Volume.ClockwiseMostAngle, -4000, 0);
});

Isn’t it brilliant?

Have a good day and be sure to read and rate my last article on Code Project :) Be good people.

Be Sociable, Share!

13 Responses to “Nifty time savers for WPF development”

  1. wekempf Says:

    Dispatcher.Invoke has an overload that takes a simple delegate, as of SP1.

    The SetBinding stuff isn’t that much of an improvement over using object initialization syntax, but that’s just an opinion.

    Otherwise, nice stuff.

  2. Top Contenders as of January 17th, 2009 - Community Credit News Says:

    [...] also added a few other articles and examples where he uses his FM Radio to demonstrate some useful XAML Time Savers.    I can see a nice potential collaboration between Tamir and Jay Smith of [...]

  3. Gianpaolo Says:

    Hi, i can use all usb radio device? the silabs do not sell more.
    You the with another device?

  4. top 5 video games for ps3 2012 Says:

    I’m gone to inform my little brother, that he should also pay a quick visi this website on regular
    basis to obtain updated from hoytest information.

  5. Odessa Says:

    I was able to fjnd goοd advice from yߋur blog articles.

    Μy weblog: raspberryultraketonetrial.org (Odessa)

  6. Susanne Says:

    My developer is trying to persuade me to move to .net
    from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious about switching to another platform.
    I have heard excellent things about blogengine.net.

    Is there a way I can transfer all my wordpress posts into it?

    Any kind of help would be really appreciated!

  7. Addicting Games Says:

    The escalating acceptance of Nintendo Wii is storming the gaming earth with every single minute
    that goes by. In this video game, you pick a breed of horse
    and customise it. Although meant mostly for younger young ones,
    people today of all ages have uncovered computer game
    titles really enjoyable and entertaining.

    My web site :: Addicting Games

  8. Alton Says:

    Oh my goodness! Amazing article dude! Thank you so much,
    However I am going through issues with your RSS.
    I don’t understand why I cannot join it. Is there anyone else
    having similar RSS issues? Anyone who knows the answer can you kindly respond?
    Thanx!!

    Take a look at my site :: cheats club penguin 2014,
    Alton,

  9. unlock that phone Says:

    Howdy! This is my first comment here so I just wanted to give a quick shout out and
    tell you I really enjoy reading your posts. Can you recommend any other blogs/websites/forums that
    cover the same topics? Thank you so much!

    My web-site: unlock that phone

  10. Clement Says:

    Hey! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  11. Shira Cobio Says:

    I think that is among the such a lot vital info for me. And
    i’m satisfied reading your article. But should remark on some bazsic issues, The sitte style is wonderful, thhe articles is truly nice : D.
    Excellent task, cheers

  12. Dell Inspiron i3531-1200BK Says:

    The Inspiron 15 is the most economical member of the family, offering a
    great combination of portability and plenty of screen real estate along with a 10-key numeric keypad next
    to the keyboard.

    Feel free to visit my webpage … Dell Inspiron i3531-1200BK

  13. นาฬิกา tag Says:

    I do not even understand how I ended up here, however I believed
    this put up was once good. I don’t know who you’re but definitely you are going to a well-known blogger should you
    are not already. Cheers!

    รู้สึกอิสระที่จะเยี่ยมชมเว็บไซต์;นาฬิกา
    tag

Leave a Reply

Recommended

 

Sponsor


Partners

WPF Disciples
Dreamhost
Code Project