October 2010



Hi,
Today I want to share with you some videos about application prototyping in Sketchflow with Expression Blend 4.
One of the new amazing feature of Blend 4.0 is the SharePoint support. In fact, Expression Blend 4 is able to publish your Sketchflow prototypes into SharePoint and in this way you can also collect and combine feedbacks coming from different SharePoint users.

I think Sketchflow is an important and useful mock-up application since allows you to share and discus prototypes in an effectively.

If you want to learn how to use Sketchflow I suggest you to download the following Sketchflow PDF GUIDE: http://www.dynamic-prototyping.com

Remember: prototyping’s activity is not time wasting. It helps in pointing out software requirement and specification allowing to better plan development activities!

Marzio.

Advertisements

Hi guys,
today I wanna share with you a MultiSelectionTreeView control that I coded by myself a couple of day ago.
The source code can be downloaded here.
Feel free to reply at this post with any question or comments you have.

The controller provide the following functionalities:

  • three different selection modalities can be specified setting SelectionMode property. Supported Selection Modalities are: 
    • SingleSelectionOnly: same behaviors of  classic WPF TreeView,
    • MultipleSelectionOnly: every click select/unselect the clicked item, 
    • KeyboardModifiersMode: multiple select  items when CTRL key is pressed
  • retrieving selected nodes using SelectedItems property
  • data binding support, including HierarchicalDataTemplate
  • tree navigation using arrows keyboards up, down and left, right for expanding and collapsing nodes
  • helpful TreeItem nodes methods like:
    • SelectAllExpandedChildren/UnselectAllChildren,
    • GetDepth,
    • GetNextNodeAtSameLevel, GetPreviousNodeAtSameLevel
  • look and feel can be overridden

The default look and feel is shown in the picture below:

Happy Coding,
Marzio.


Hi!,
Today I just want to provide a quick fix for removing Black Background Popup in WPF.
For removing Black Background you just need to set AllowsTransparency property to True, and that’s all 😉
And, off course, after that you can insert a Border, as well as a Grid, and setting your preferred background color.

<Popup PlacementTarget="{Binding ElementName=myUIElement}"
           Placement="Center" 
           AllowsTransparency="True"
           HorizontalAlignment="Center" 
           VerticalAlignment="Center" >

   <Border Background="White" ...
      ...
   </Border>

</Popup>

Marzio.


Hi guys!
The missed binding updating after coercing a DP value was resolved only partially in my previous post. In fact the issue is still present when the binded DP type is a String!
Below my sample application screenshot downloadable here.

And, sure, here you are the new definitely fix 😉

        public string MyValue
        {
            get { return (string)GetValue(MyValueProperty); }
            set { SetValue(MyValueProperty, value); }
        }
        public static readonly DependencyProperty MyValueProperty =
            DependencyProperty.Register("MyValue", typeof(string), typeof(Window1), new UIPropertyMetadata("50", new PropertyChangedCallback(MyValueChanged), new CoerceValueCallback(MyValueCoerceValue)));

        private static void MyValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Window1 w1 = d as Window1;
            w1._txtBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
        }

        private static object MyValueCoerceValue(DependencyObject d, object value)
        {
            string intValue = (string)value;

            if (Int32.Parse(intValue) < 0)
                intValue = "0";
            else if (Int32.Parse(intValue) > 100)
                intValue = "100";

            Window1 w1 = d as Window1;
            w1._txtBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();

            return intValue;
        }

You are may asking “why it is necessary forcing binding UpdateTarget() both in CoerceValue and PropertyChanged callbacks”?

  • UpdateTarget() in PropertyChanged: in this way we ensure that the displayed text is updated every time MyValue DP has been changed. However, what happens when the current value is “100” and the user insert “1000”? The CoerceValue sets MyValue DP to 100 but, since the old value (100) is equal to new value (100), the PropertyChanged is not called! Consequently, the TextBox still displays the last typed value (1000)!
  • UpdateTarget() in CoerceValue: in this way we cover the scenario in which the current value is “100” and the user insert a value greater than 100 (e.g. 1000).
  • Honestly, I didn’t understood the reason why in case of “int” DP property a single call of UpdateTarget() on CoerceValue is sufficient to update the displayed value.

    Happy coding!
    Marzio.


    Please, for definitely fix see the second part of this article 😉

    Hi!
    Today I spent 2 hours of my coding in understanding the reason why a TextBox didn’t display a new value set by CoerceValue Callback!

    Click here to download the example.

    This is the XAML code containing the Text property binding.

    <Window x:Class="TextBindingAndCoerceValue.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="Binding and CoerceValue" 
        Height="300" 
        Width="300">
        
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Label Content="Insert Value (0-100):" VerticalAlignment="Center"/>
                <TextBox Name="_txtBox" Margin="5" Text="{Binding MyValue, Mode=TwoWay}" HorizontalAlignment="Stretch" Width="152"/>
            </StackPanel>
            <Button Margin="5" Content="Set New Value"/>
        </StackPanel>
        
    </Window>
    

    And here you are the code behind (affected with described issue).

        public partial class Window1 : Window
        {
    
            public int MyValue
            {
                get { return (int)GetValue(MyValueProperty); }
                set { SetValue(MyValueProperty, value); }
            }
            public static readonly DependencyProperty MyValueProperty =
                DependencyProperty.Register("MyValue", typeof(int), typeof(Window1), new UIPropertyMetadata(0, new PropertyChangedCallback(MyValueChanged), new CoerceValueCallback(MyValueCoerceValue)));
    
            private static void MyValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
            }
    
            private static object MyValueCoerceValue(DependencyObject d, object value)
            {
                int intValue = (int)value;
    
                if (intValue < 0)
                    intValue = 0;
                else if (intValue > 100)
                    intValue = 100;
    
                return intValue;
            }
    
    
            public Window1()
            {
                InitializeComponent();
            }
        }
    

    The problem is that MyValue Dependency Property is properly updated when inserting a value less than 0 or greater than 100, but the TextBlock still display the just typed value!
    Honestly I didn’t understood the real cause of the problem and every WPF developers should expect TwoWay binding to display coerced value! Instead, even with a binding, the text block is still presenting what is typed into it ignoring the update!

    As developer, you need to force a target update on the binding (via UpdateTarget()) when the coersion fails if you want to display the coerced value. Here you are the problem fixing:

    
            private static object MyValueCoerceValue(DependencyObject d, object value)
            {
                int intValue = (int)value;
    
                if (intValue < 0)
                    intValue = 0;
                else if (intValue > 100)
                    intValue = 100;
    
                Window1 w1 = d as Window1;
                w1._txtBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
    
                return intValue;
            }
    
    

    Happy coding,
    Marzio.


    Hi guys,
    few days after using Visual Studio 2008 on Windows 7, it happens that Visual Studio losts XAML intellisense functionality, making my coding very annoying.
    The issue is well known in Microsoft Community, even if the cause is not so clear in my opinion: http://social.msdn.microsoft.com/forums/en-US/windowssdk/thread/dd6f14ed-e582-4b49-9358-64f2afaec151/


    The faster fix consists in manually registering the TextMgrP.dll:

    On an X86 machine:

    1. Open a Windows CMD window as an Administrator (On Vista: Start, All Programs, Accessories, right-click on command prompt and  choose to Run as Administrator)
    2. Type: regsvr32 “%CommonProgramFiles%\Microsoft Shared\MSEnv\TextMgrP.dll”

    On an X64 machine:

    1. Open a Windows CMD window as an Administrator (On Vista: Start, All Programs, Accessories, right-click on command prompt and  choose to Run as Administrator)
    2. Type: regsvr32 “%CommonProgramFiles(X86)%\Microsoft Shared\MSEnv\TextMgrP.dll”

    After that don’t forget to close all opened Visual Studio and launch them again 🙂


    The described procedure solved my problem.

    Stay tuned,
    Marzio.