Sonntag, 30. Januar 2011

Windows Phone 7 Update Troubleshooting

We all waiting for the NoDo-Update – some sources announce the update around the 7th of February. But Microsoft looking forward and have now published a knowledge base article about troubleshooting problems during the update process of Windows Phone 7 (hope that there are not a lot of)

Troubleshooting problems during software update for Windows Phone 7

Samstag, 29. Januar 2011

Windows Phone 7: GPS emulator

In your Windows Phone device you have a built-in Assisted GPS (aGPS), which can be used to access location informations by using the System.Device.Location namespace. The GeoCoordinateWatcher class supplies location data based on latitude and longitude coordinates. This is nice, but if you want to develop such an application it is necessary to emulate the GPS sensor.

In this Windows Phone Team Blog a very good article can be found to achieve this goal.

Dienstag, 18. Januar 2011

Debugging Windows Phone 7 device traffic with Fiddler

Eric Law on his MSDN blog has detailed a method using Fiddler to watch your phone's data traffic over WiFi (so this won't help with that 3G issue). Primarily this is a great tool for developers to make sure their app is not using excess data in any way but it can also be useful for those who just want to know what's going on.

Debugging Windows Phone 7 device traffic with Fiddler - Fiddler Web Debugger - Site Home - MSDN Blogs

Montag, 17. Januar 2011

Data Access with Windows Phone 7

My article in the german Dotnetpro magazine about data access with Windows Phone 7, I have written with my SDX colleage Matthias (see Mind-driven development), is now out: http://bit.ly/hzYWFC

Dienstag, 14. Dezember 2010

Windows Phone recipes – Open source projects

Windows Phone recipes are open source (MSPL) projects aimed at helping Windows Phone developers with their Windows Phone applications. Recipes are usually common patterns for topics that require some attention. The idea is to provide a sample with some reusable code that can be reused later and modified to fit other similar scenarios. Developers are more than welcome to use them as is, or to change them as they see fit.

Windows Phone Recipes – Helping the Community

Samstag, 11. Dezember 2010

Windows Phone 7: Grid style listbox

If you want to implement a grid for your Windows Phone 7 app you have to use a Listbox control because of the missing DataGrid at the Windows Phone 7 platform. A first idea for contsructing a Grid then could be to use the WrapPanel control in your ItemTemplate of the Listbox control. But if you do this, the data virtualization of the ListBox will be disabled (Virtualizing Data in Windows Phone 7 Silverlight Applications - Peter Torr's Blog - Site Home - MSDN Blogs). This will increase the loading time of your ListBox and results in a very poor UX handling. The problem is, that you can not use any complex data structures in the ItemTemplate at a Listbox for Windows Phone 7. Every line in the Listbox should be one data line. So a solution for developing a grid styled Listbox is to implement a RowAdapter class for your bounded data.

Here a implementation of a RowAdapter, I used in one of my projects:

public class RowAdapter<TItemType> : IList<IEnumerable<TItemType>>, INotifyCollectionChanged
    {
        private readonly IList<TItemType> _sourceList;
        private readonly int _columns;
 
        private class RowObject : IEnumerable<TItemType>
        {
            internal readonly RowAdapter<TItemType> Parent;
            internal readonly int StartIndex;
 
            public RowObject(RowAdapter<TItemType> parent, int startIndex)
            {
                Parent = parent;
                StartIndex = startIndex;
            }
 
            #region IEnumerable<TItemType> Members
 
            public IEnumerator<TItemType> GetEnumerator()
            {
                int limit = Parent._sourceList.Count;
                int end = Math.Min(StartIndex + Parent._columns, limit);
 
                for (int pos = StartIndex; pos < end; ++pos)
                {
                    yield return Parent._sourceList[pos];
                }
            }
 
            #endregion
 
            #region IEnumerable Members
 
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
 
            #endregion
        }
 
        public RowAdapter(IList<TItemType> sourceList, int columns)
        {
            if (null == sourceList)
                throw new ArgumentNullException("sourceList", Resource.RowAdapter_RowAdapter_sourceList_is_null);
            if (columns <= 0)
                throw new ArgumentOutOfRangeException("columns", Resource.RowAdapter_RowAdapter_ColumnsGreaterOne);
 
            // We require the source list to implement IList because we
            // need to know how many item there are
            _sourceList = sourceList;
            _columns = columns;
 
            var sourceNotify = sourceList as INotifyCollectionChanged;
            if (null != sourceNotify)
            {
                sourceNotify.CollectionChanged += OnSourceCollectionChanged;
            }
        }
 
        #region IList<IEnumerable<TItemType>> Members
 
        public int IndexOf(IEnumerable<TItemType> item)
        {
            var realItem = item as RowObject;
            if (null == realItem || !ReferenceEquals(realItem.Parent, this))
                return -1;          // It does not belong to this collection
 
            Debug.Assert(0 == realItem.StartIndex % _columns, "RowObject item has a wierd index");
            return realItem.StartIndex / _columns;
        }
 
        public void Insert(int index, IEnumerable<TItemType> item)
        {
            throw new NotSupportedException();
        }
 
        public IEnumerable<TItemType> this[int index]
        {
            get
            {
                if (index < 0 || index > Count)
                    return null;
 
                return InternalGetRow(index);
            }
            set
            {
                throw new NotSupportedException();
            }
        }
 
        public void RemoveAt(int index)
        {
            throw new NotSupportedException();
        }
 
        #endregion
 
        #region ICollection<IEnumerable<TItemType>> Members
 
        public void Add(IEnumerable<TItemType> item)
        {
            throw new NotSupportedException();
        }
 
        public bool Contains(IEnumerable<TItemType> item)
        {
            var realItem = item as RowObject;
            return null != realItem && object.ReferenceEquals(realItem.Parent, this);
        }
 
        public void CopyTo(IEnumerable<TItemType>[] array, int arrayIndex)
        {
            // I haven't implemented this. It is easy to implement if you need it
            throw new NotImplementedException();
        }
 
        public bool Remove(IEnumerable<TItemType> item)
        {
            throw new NotSupportedException();
        }
        public void Clear()
        {
            throw new NotSupportedException();
        }
 
        public int Count
        {
            get
            {
                return (_sourceList.Count + (_columns - 1)) / _columns;
            }
        }
 
        public bool IsReadOnly
        {
            get { return true; }
        }
 
        #endregion
 
        #region IEnumerable<IEnumerable<TItemType>> Members
 
        public IEnumerator<IEnumerable<TItemType>> GetEnumerator()
        {
            for (int i = 0; i < Count; ++i)
            {
                yield return InternalGetRow(i);
            }
        }
 
        #endregion
 
        #region IEnumerable Members
 
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
 
        #endregion
 
        #region INotifyCollectionChanged Members
 
        public event NotifyCollectionChangedEventHandler CollectionChanged;
 
        private void FireCollectionChanged()
        {
            
            var handler = CollectionChanged;
            if (null != handler)
            {
                handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
 
        private void OnSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            FireCollectionChanged();
        }
 
        #endregion
 
        private RowObject InternalGetRow(int index)
        {
           return new RowObject(this, index * _columns);
        }
    }