DCSIMG
October 2007 - Posts - Just code - Tamir Khason

October 2007 - Posts

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/is-it-dell-in-israel-or-x5-prices-of-dell-accessories/]


Those, who remember my posts about Dell Israel, probably know what I'm going to talk about. How much costs Dell Latitude D820 keyboard (part number: UC172) in Israel?

image

Well, shipping, handling, etc... Let's say another 20$ (it's almost twice). So, $13.59 + $20 = $33.59. Well, they should be profitable, so another 10% = $1.36. You know what, 25% = $3.4. OK, ok, this is little money, so $40.

I just received the proposal from the well known company, which is authorized distribute of Dell in Israel as following $135 (+VAT).

image

I called general manager of the company and asked him the simple question: "WHY?". He responded: $75 - the keyboard + work. Well, 65$ for keyboard installation (even in laptop) takes about 15 minutes. So their technicians earns much more then software architects and consulters, about 260$/hour. Maybe I got a wrong job?

But, let's leave technicians alone and see their earn margins - it's 500%. Pretty good, isn't it?

I tried to call Dell Israel to get answers, but no one  (of 10 extensions) did not even poke a phone. I'll send them and their parent company an email to ask about their price policy. Maybe this way I'll be less surprised about such prices...

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/silverlight-installation-experience/]


You are, probably, know who looks Silverlight installation. Logo calls for download -> another page -> EULA -> another page -> download file -> another page -> look for the file, just downloaded -> run it -> close and reopen everything to be sure, that Sivlerlight runtime was installed. The same way for other browser type (in case, you have some). This was the only avaliable way to install Silverlight... until today. See this installation experience guide, that illustrates direct (recommended) and indirect way to install Silverlight runtime engine. Great work (includes code samples)!

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/how-to-turn-off-autorecovery-feature-of-microsoft-office/]


Autorecovery is greate feature of Microsoft Office. I my memory is ok, it was introduces in Office 2003. That's great, but it might drive you (and your client) crazy, when you are using any of MS Office applications inside your own application (e.g. showing Word or PowerPoint document inside WinForms. Any "unsafe" dispose of ActiveDocument object forces Office to pop up following message

How to turn it off? Just go to Tools->Options->Save and check Disable AutoRecovery checkbox. If you want to do it from code, you can find

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/autocomplete-textbox-in-wpf-well-almost/]


Autocomplete textbox is missing control in WPF 3.0 and WPF 3.5. Is it true? Actually, WPF is very extensible language, thus it is almost work nothing to build user control, derrived from TextBox to achive autocomplete functionality. But are we really have to do it? Let's try to understand which control can provide us with similar functionality. I'm beting on ComboBox.

<ComboBox>
 
<TextBlock>Hello</TextBlock>
 <TextBlock>World</TextBlock>
 <TextBlock>This</TextBlock>
 <TextBlock>is</TextBlock>
 <TextBlock>Autocomplete</TextBlock>
 <TextBlock>Textbox</TextBlock>
</ComboBox>

Now we have to make the combobox editable. So, let's set IsEditable property to True. Ok, I can write, but can not select. ComboBox control provides us with option to choose items by typing its values. This works only when the ComboBox is opened. So we have to force the ComboBox to open its items and leave them opened while typing without pressing the arrow sign at the right. If I'll bet on IsDropDownOpen property, I'll be wrong, 'cos I not need to see itesm, I want only select them. Another property looks interesting is IsTextSearchEnabled. Let's see MSDN to understand what this property do... "Enables a user to quickly access items in a set by typing prefixes of strings". Wow, that's exactly what I need. But... what the default value? It's True, so I'm not really need to set it. Let's see, how can I force items to be opened while typing. Got it - StaysOpenOnEdit property.

Now, if I'll put IsEditable="True" StaysOpenOnEdit="True" I'll make my ComboBox to accept keystrokes to choose items without openning items panel. And that exactly what I need. So, now ComboBox with those two properties set to True converts into regular TextBox with autocomplition functionality. The only thing you should do (if you really want to), is to change control template to remove triangle button at right.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/call-for-action-command-and-control-by-using-microsoft-technology/]


This is an invitation to attend at the event, arranged by Microsoft Israel and mPrest systems about building Homeland security, C&C and other military systems, by using latest Microsoft technologies. The event will take part at 26-Dec (8:30AM - 1:30PM) at Microsoft Israel building in Ra'anana.

Agenda:

  • C&C Windows and Web client development by using WPF and Silverlight - Myself
  • State-of-Art C&C server (mCore) and generic client development - Eli Arlazoroff
  • WCF + Virtual Earth for mission data visualization - Lior Rozner

If you are in military or other RT industry, this is one of "must attend" events. Register@MSEvents.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/rtl-support-for-silverlight-community-sneak-preview/]


About three months ago, I blogged about work-around solution to display right-to-left text in Silverlight. A bit after, Microsoft MVP Justin-Josef Angel begun to work on real solution. And today it's ready. I checked a code, posted on Microsoft development community site CodePlex and found it very nice and useful. So, if you have a problem with Hebrew, Arabic or any other RTL language in Silverlight. Use it (you can try it or see webcast as well), before manufacture's  solution will come (and it'll come, I believe, some day). Very nice work, Justin!

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/windows-live-gallery-wave-2-update-commercial/]


Cool new update come today to Windows Live Gallery. Now you, as developers can sell your gadgets and as customers to buy them. Money tree? Not exactly. Purchasing or selling might be done by using Microsoft Points (those of XBox). Cool feature, that, probably, will increase the amount of available gadgets, by motivating developers to build and sell them. Meanwhile all my gadgets are fee :)

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/clipboard-setdata-getdata-troubles-with-vpc-and-ts/]


This one of those posts you can categorize is WTF (see me WPF presentation to know what is it) it is not working. However, you, probably will face with the problem now or after.

Symptoms: You are trying to set and get clipboard data from Virtual PC or remote computer by using Terminal Services and nothing happens. When you are using .NET, you're getting Unhandled exception. If you'll dig deeper, you'll find 0x800401D0 (CLIPBRD_E_CANT_OPEN) exception.

Reason: Passing data through TS or VPC pipes bug

Solution: Just retry a couple of times.

Actually, in unmanaged and COM world, you'll never face this problem, because of the way we are handling OleSetClipboard() and OleGetClipboard() methods (which wrapped by .NET Clipboard.GetData/Clipboard.SetData Set/Get Text etc. methods).  So, something like following functions will solve your problems.

public static IDataObject GetRemoteClipboardDataObject()
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    return Clipboard.GetDataObject();
                }
                catch { }
                System.Threading.Thread.Sleep(100);
            }
        }

public static void SetRemoteClipboardDataObject(object data)
        {
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Clipboard.SetDataObject(data);
                    return;
                }
                catch { }
                System.Threading.Thread.Sleep(100);
            }
        }

Now, to be honest with myself, take a look into one of Clipboard.SetDataObject method signatures in .NET framework 2.0

//Attempts to place data on the system Clipboard the specified number of times and with the specified delay between attempts, optionally leaving the data on the Clipboard after the application exits. 
public static void SetDataObject (
    Object data,
    bool copy,
    int retryTimes,
    int retryDelay
)
Don't it looks familiar? :) Have a nice day and be honest with yourselves.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/california-wildfires/]


To all my friends and co-workers from California region - take care and be strong!

View image detail

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/merge-your-live-accounts/]


New huge feature was added to wave 2 of Windows.Live - merging of Live accounts. Just go to this page and merge all of them. From now, you can use all Live products by choosing proper account from upper right corner, rather then relogin with other credentials.

via LifeSide

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/how-to-filter-itemscontrol-view-rather-then-data-source/]


How to filter data source of ItemsControl, you, probably, know, but what to do, when you want to filter view of the control's items, rather then the data behind? What's the strange requirement, you'll ask. I'll give you very simple example for business case, when you need to filter only what you are viewing in ListBox or any other items control, rather then data behind. You have two listboxes bounded to the same data source. In one, and only one, of those listboxes you want to filter data. What to do?

image

If  you'll filter data by using CollectionViewSource.GetDefaultView(YourListBox.ItemsSource).Filter = new Predicate(FilterOdds) statement or, even YourListBox.Items.Filter = new Predicate(FilterOdds) statement, you'll filter data in both ListBoxes. This is not what you want. You need to filter the view of the data and not a data itself.

Just enumerate listbox items and Collapse "unnecessaries", according predefined criteria. Like following:

for (int i = 0; i < MyListBox.Items.Count; i++)
{
  ListBoxItem itm = MyListBox.Items[i] as ListBoxItem;
   if (FilterOdds(itm.Content))
    MyListBox.Items[i].Visibility = Visibility.Collapsed;
}

image

But, if you want to be even more precise, pay attention on what has been virtualized and what has not by getting underlying VirtualizingStackPanel and enumerating and operating it's items. How to do it? Get and see in source code for this article.

UPD: This article was read by a couple of hundrends of visitors, however only one sent me an e-mail (comments are not working?) about a mistake. Try to imagine, that data source was changed. What are you think will happen to bounded listbox? That's right, this will not be updated, due to fact, that we filtered view, not source. What to do? When you want to filter your view, subscribe to DataChanged event of it's data source. There perform filterring. Don't forget to unsubscribe, when you're removing the filter.

Source code was updated. Please, fix my mistakes. I'm only human and sometimes (not too ofter) I'm getting wrong... Tnx to Zahi, who notice me about an error.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/how-to-build-dynamic-menus-and-toolbars/]


The challenge is as following:

  • I want to have external XAML files with menus and toolbars
  • I do not want to recompile project if I want to change something in those menus and toolbars
  • I want to provide commands for those menus and toolbars without recompiling
  • I want to write least amount of code to provide such functionality

What's the problem? The answer is XamlReader. First let's create menus and toolbars in external loose XAML files and put them into our BIN directory.

Menu1.xaml

<Menu xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <MenuItem Header="Edit">
    <MenuItem Command="ApplicationCommands.Cut"/>
    <MenuItem Command="ApplicationCommands.Copy"/>
    <MenuItem Command="ApplicationCommands.Paste"/>
  </MenuItem>
</Menu>

ToolBar1.xaml

<ToolBar xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Button Command="ApplicationCommands.Cut">
    <Image Source="pack://siteoforigin:,,,/cut.png"/>
  </Button>
    <Button Command="ApplicationCommands.Copy">
      <Image Source="pack://siteoforigin:,,,/copy.png"/>
    </Button>
    <Button Command="ApplicationCommands.Paste">
      <Image Source="pack://siteoforigin:,,,/paste.png"/>
    </Button>
</ToolBar>

Now let's create out window

Window1.xaml

<Window x:Class="DynamicMenu.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DynamicMenu" Height="300" Width="300"
    >
  <Window.Resources>
    <Style TargetType="Image">
      <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Opacity" Value="0.5"/>
        </Trigger>
      </Style.Triggers>
    </Style>
  </Window.Resources>
    <StackPanel Name="main">
      <TextBox/>
      <TextBox/>
    </StackPanel>
</Window>

Now, the only thing we should do it to read Menu1.xaml and TooBar1.xaml from our BIN directory and add Menu and ToolBar controls dynamically to the page

public Window1()
       {
           InitializeComponent();
           using (FileStream s = new FileStream("Menu1.xaml", FileMode.Open))
           {
               Menu menu = XamlReader.Load(s, new ParserContext()) as Menu;
               if (menu != null)
               {
                   main.Children.Insert(0, menu);
               }
           }
           using (FileStream s = new FileStream("ToolBar1.xaml", FileMode.Open))
           {
               ToolBar tool = XamlReader.Load(s, new ParserContext()) as ToolBar;
               if (tool != null)
               {
                   main.Children.Insert(1, tool);
               }
           }
       }

image

We done. Have a nice day :)

Source code for this article

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/just-mood/]


ATT3249910[1]

Comments are over here            

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/very-useful-excel-feature/]


After Excel bugs, where resolved, I started to pay attention to what this program provides me. I noticed about very useful feature of automatic calculation of averages and summaries of selected cells. Here the really useful result of such feature. Long life, Excel 2007

image

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/sorted-dictionary-class-for-silverlight/]


Yes, Silverlight 1.1 is far from being perfect. It's lack of some very important classes. The good example for it is SortedDictionary and binary search tree. Why it's so important and what top-down (red-black) binary search trees are?

If you want to use generic dictionary not only for storing key-value information, but also for searching and accessing data by other criteria,  you, probably, can implement IComparable interface and for each new data entry or update resort whole list. But, if you are looking not only for such functionality, but, also, for performance, you'd like to use black-red trees to achieve the behavior.  So, what we really have?

  • Our data exists in Key-Value pairs
  • Total order of items is predefined
  • We can sort by such criteria keys and values and not only keys.

All those features are defined by Binary Search Tree (or BST). But SortedDictionary is maintaining not only those trees, but, also, the criteria or, other words, the order. It also uses sequential algorithm to locate keys. SortedList has linear search time, as the last key in the list will require comparisons to every preceding key, so item insertion, removal and retrieval time will be O(log n) contrasts SortedList, that inserts and removes items with O(n) time and lookup O(log n). So, it's obvious, that SortedDictionary works much faster with large amount of frequent changing data. However, it uses much more objects on heap, due to fact, that all of it's items are linked together with tree, wrapped in a Node (that internally implemented reference type)

Each application should choose what type of sorted collections to use, however, it's really important to understand, that even in SL application, we should have SortedDictionary class.

I got shared source CLI for 2.0 (ECMA CLI and C# for XP), which is freely available through MSDN and wrap and fix SortedDictionary class to be used within Silverlight constraints. So, if you need such class in your Silverlight application, download it here.

More Posts Next page »