Tuesday, March 25, 2014

Scrollable Expandable Control's problem

Scrollable-expandable-controls problem.
Scrollable-expandable-controls : are controls that can stretch as its content grows and will display scrollbars when their size is restricted.
Problem appears when they are located inside another scrollable control. Child scrollable-expandable-controls will keep expanding and will count on the outer scrollable control's scrollbars.
if you give it a maximum width or height problem will be resolved but you will need to know the size ahead and you don't have this privilege if you want a dynamic app that works well with all different screen sizes.
in order to achieve required behavior , we need a panel in between to allow its children (scrollable-expandable-control) to grow. Asking them to give the minimum required size and then give them the maximum size the parent provides without displaying scrollbars , currently there is no panel like this.

Here is a one that I developed to provide this functionality:
    class LimitChild : System.Windows.Controls.Panel
    {
        public LimitChild()
        {
        }

        protected override Size MeasureOverride(System.Windows.Size availableSize)
        {
            System.Diagnostics.Debug.Assert(InternalChildren.Count == 1);
            System.Windows.UIElement child = InternalChildren[0];

            Size panelDesiredSize = new Size();
            // panelDesiredSize.Width = availableSize.Width;
            panelDesiredSize.Width = (double)child.GetValue(FrameworkElement.MinWidthProperty);
            panelDesiredSize.Height = (double)child.GetValue(FrameworkElement.MinHeightProperty);

            child.Measure(panelDesiredSize);

            // IMPORTANT: do not allow PositiveInfinity to be returned, that will raise an exception in the caller! 
            // PositiveInfinity might be an availableSize input; this means that the parent does not care about sizing 
            return panelDesiredSize;
        }

        protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
        {
            System.Windows.UIElement child = InternalChildren[0];

            child.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
            if (finalSize.Width > child.RenderSize.Width)
                finalSize.Width = child.RenderSize.Width;
            if (finalSize.Height > child.RenderSize.Height)
                finalSize.Height = child.RenderSize.Height;

            return finalSize; // Returns the final Arranged size
        }
    }
and then inside your xaml surround your scrollable-expandable-control with a LimitChild panel.

Monday, March 24, 2014

SugarSync Review

I only tried to use it for one day, and I found all of these defects:

the client software that I install on my computer:
- I cannot log off and log in in a different user name. Once you log in you are stuck.
- some of the folders that are shared with me by other friends , their "sync to my computer" toggle button is completely disabled.
- The folder that I managed to turn its sync-to-my-computer toggle button on, SugarSync failed to sync it. It has a 3 GB file inside it. It says that sync is successful and complete, but actually the file is not in the folder. (P.S: I tried to increase the cache up to 8 GB but did not help.)
- Froze several times and became unresponsive. and I had to kill it every time.
- crashed once.


When I tried to access the Website directly , I faced the following Problems:
- it claims that download was successful and I end up with a broken file.
- if download is interrupted, there is no resume download feature.
- When I download a folder , I end up with 3 or 4 of the downloaded files with 0 KB (empty files). Knowing that they are at least few 3KBs in size but still I receive them with 0 KB and status is downloaded successfully.

Sunday, March 23, 2014

Unaligned Column Header with Data

I am very happy today that I solves a problem that I have been facing for a long time.
:->

When you have a custom control template, column headers will be shifted to the left unshowing the Select All button while the DataGrid cells manage to recognize the row header and shift correctly. Resulting in a column header that is not aligned with its corresponding cells.

CAUSE : some people would think it is the Visibility of the select all button but this is very untrue. The truth is that Width of this button is bound to an un-updated-properly property CellsPanelHorizontalOffset . Simply put , DataGrid fails to update this property accurately , ending up with value (most of the time) equals ZERO.

SOLUTION : bind the Select All button Width to RowHeaderActualWidth and enjoy the magic ;-)