Friday, January 21, 2011

AutoLoading more content when you scroll to the bottom of a ListBox in WP7 (Windows Phone 7)

I've just implemented this for Overflow7.

The approach I took was similar to http://blog.slimcode.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/

However, instead of using a Style I did the hook up in code.

Basically derived my parent UserControl from:

     public class BaseExtendedListUserControl : UserControl
{
   
DependencyProperty ListVerticalOffsetProperty = DependencyProperty.Register(
     
"ListVerticalOffset",
     
typeof(double),
     
typeof(BaseExtendedListUserControl),
     
new PropertyMetadata(new PropertyChangedCallback(OnListVerticalOffsetChanged)));

   
private ScrollViewer _listScrollViewer;

   
protected void EnsureBoundToScrollViewer()
   
{
       
if (_listScrollViewer != null)
           
return;

       
var elements = VisualTreeHelper.FindElementsInHostCoordinates(new Rect(0,0,this.Width, this.Height), this);

        _listScrollViewer
= elements.Where(x => x is ScrollViewer).FirstOrDefault() as ScrollViewer;

       
if (_listScrollViewer == null)
           
return;

       
Binding binding = new Binding();
        binding
.Source = _listScrollViewer;
        binding
.Path = new PropertyPath("VerticalOffset");
        binding
.Mode = BindingMode.OneWay;
       
this.SetBinding(ListVerticalOffsetProperty, binding);
   
}

   
public double ListVerticalOffset
   
{
        get
{ return (double)this.GetValue(ListVerticalOffsetProperty); }
        set
{ this.SetValue(ListVerticalOffsetProperty, value); }
   
}

   
private static void OnListVerticalOffsetChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
   
{
       
BaseExtendedListUserControl control = obj as BaseExtendedListUserControl;
        control
.OnListVerticalOffsetChanged();
   
}

   
private void OnListVerticalOffsetChanged()
   
{
       
OnListVerticalOffsetChanged(_listScrollViewer);

   
}

   
protected virtual void OnListVerticalOffsetChanged(ScrollViewer s)
   
{
       
// do nothing
   
}
}

this then meant that in the user control itself I could just use:

         protected override void OnListVerticalOffsetChanged(ScrollViewer viewer)
   
{
       
// Trigger when at the end of the viewport
       
if (viewer.VerticalOffset >= viewer.ScrollableHeight)
       
{
                // actually do the load here!
        }
   
}

   
private void ListBox1_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
   
{
       
EnsureBoundToScrollViewer();
   
}

The "hacky" thing here was that I had to use ListBox1_ManipulationCompleted and VisualTreeHelper to find my ScrollViewer - I'm sure there are better ways...

Wednesday, January 19, 2011

TextWrapping for HyperlinkButton on Windows Phone 7 WP7

Thanks to MisterGoodcat!

From:

This is the magic style:
 <Style x:Key="HyperlinkButtonWrappingStyle"         TargetType="HyperlinkButton">     <Setter Property="Foreground"             Value="{StaticResource PhoneForegroundBrush}" />     <Setter Property="Background"             Value="Transparent" />     <Setter Property="FontSize"             Value="{StaticResource PhoneFontSizeMedium}" />     <Setter Property="Padding"             Value="0" />     <Setter Property="Template">         <Setter.Value>             <ControlTemplate TargetType="HyperlinkButton">                 <Border Background="Transparent">                     <VisualStateManager.VisualStateGroups>                         <VisualStateGroup x:Name="CommonStates">                             <VisualState x:Name="Normal" />                             <VisualState x:Name="MouseOver" />                             <VisualState x:Name="Pressed">                                 <Storyboard>                                     <DoubleAnimation Duration="0"                                                         To="0.5"                                                         Storyboard.TargetProperty="Opacity"                                                         Storyboard.TargetName="TextElement" />                                 </Storyboard>                             </VisualState>                             <VisualState x:Name="Disabled">                                 <Storyboard>                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"                                                                     Storyboard.TargetName="TextElement">                                         <DiscreteObjectKeyFrame KeyTime="0"                                                                 Value="{StaticResource PhoneDisabledBrush}" />                                     </ObjectAnimationUsingKeyFrames>                                 </Storyboard>                             </VisualState>                         </VisualStateGroup>                     </VisualStateManager.VisualStateGroups>                     <Border Background="{TemplateBinding Background}"                             Margin="{StaticResource PhoneHorizontalMargin}"                             Padding="{TemplateBinding Padding}">                         <TextBlock x:Name="TextElement"                                     HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"                                     Text="{TemplateBinding Content}"                                     TextDecorations="Underline"                                     VerticalAlignment="{TemplateBinding VerticalContentAlignment}"                                     TextWrapping="Wrap" />                     </Border>                 </Border>             </ControlTemplate>         </Setter.Value>     </Setter> </Style>

Thursday, January 13, 2011

Important Update - for submitting to WP7 Marketplace

Further to this marketplace advice: http://slodge.blogspot.com/2010/11/marketplace-advice-for-wp7-windows.html

This year I've discovered that the Marketplace is getting very strict on making sure apps include:
- App Name
- Version Number
- Support contact info

You have been warned!

iron7

iron7 is an IronRuby scripting environment for WP7

Not sure I can explain it very easily in words - maybe better to just show you these videos and to point you to http://www.iron7.com and http://script.iron7.com






Recent App Experiments

Not blogged here much recently... sorry!

Main reason is because I've been posting info over on http://iron7.com

This includes an MVC3 Razor app linking to jquerymobile - see http://script.iron7.com

However, to make up for this, here's a video of my latest WP7 app - a translation app called Translate-A-Bull - it includes: audio and animation - yes, that's right I finally used Expression Blend!

Here's a video:

One of my new favourite coding toys

I'm still very new to this Silverlight game... and there really doesn't seem to be much "XAML" out there for people to use in animations.

However.... this converter turns SVG into XAML - and there are heaps of free SVG images out there:
http://www.graphspe.com/svg-to-xaml-converter#/Converter

There are a few issues with the converter (doesn't quite work perfectly for WP7) but overall it's great!

Aside: There's also a codeplex project called XamlTune - but I couldn't get that to work on my XAML - it kept crashing :/ 


Wednesday, January 12, 2011

Some stats on WP7 App Sales


RunSat Free:


RunSat Full:

Note that the full app includes both "trial" and "paid" apps - about 20% are paid (so I've sold about 100 copies so far!)

One more set of stats - so far:
  • 35 reviews of RunSat Free - ~0.5%
  • 8 reviews of RunSat Full - ~2%

I've not thought deeply about these stats - I'll let others make their own conclusions for now!