Tuesday, 22 September 2009

WPF: Defining a style based on the base style

<Style TargetType="ToggleButton" BasedOn="{StaticResource {x:Type ToggleButton}}">

The VS2008 IDE fails to render the XAML correctly if you try to modify an existing Style for a Component. It does still compile and excute correctly however.

A ListViewItem Style for example:

<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Style.Triggers>
<Trigger Property="ListViewItem.IsMouseOver" Value="True">
<Setter Property="ListViewItem.IsSelected" Value="true"></Setter>
</Trigger>
</Style.Triggers>
</Style>

Tuesday, 15 September 2009

MVVM: Silverlight versus WPF

In order to use the Command model for Silverlight it is necessary to download the Prism for Silverlight extensions

Silverlight Prism extension

Alternatively it is possible to place a click event inside view behind on Silverlight view then cast Datacontext to ViewModel and execute methods

add to the View code behind

Button_Click(object sender,RoutedEventArgs e)
{
var data = this.DataContext as ViewModel;

data.MyMethod();
}

Saturday, 12 September 2009

Windows CE Programming

1. Detect version using cgacutil

Friday, 11 September 2009

WPF

Test for Design Mode:
DesignerProperties.GetIsInDesignMode

Access framework property Metadata:
FrameworkPropertyMetaData fpmd = new TextBox.TextProperty.GetMetadata(typeof(TextBox)) as FrameworkPropertyElement;
bool bindingDirectionByDefault = fpmd.BindsTwoWayByDefault;

Changing List Selected Item on TextBox GotFocus:

<listview.itemcontainerstyle>
<style targettype="ListViewItem">
<setter property="HorizontalContentAlignment" value="Stretch"></setter>
<eventsetter event="GotFocus" handler="TextBox_GotFocus"></eventsetter>
</style>
</listview.itemcontainerstyle>



private void Item_GotFocus(object sender, RoutedEventArgs e)
{
ListViewItem item = sender as ListViewItem;
this.parameterList.SelectedItem = item.DataContext;
}

Friday, 4 September 2009

Threading Issues

WPF Threading issues

Exception Thrown "The calling thread cannot access this object because a different thread owns it".

When hooking up Images using a MVVM pattern and background threads this
Exception Thrown "The calling thread cannot access this object because a different thread owns it".
Use Image.Freeze() command to prevent this.

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5975d3f5-9771-442f-a11e-183b4969e38d/


Again MVVM this time button does not update its valid state following a background thread.

Normally the WPF infrastructure updates every command`s enabled/disabled state but in this case need to refresh the command`s enabled/disabled state manually.
Use InvalidateRequestQuery.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d2cf8ff9-eecd-40ec-b3a1-c8c8e39378d9

This is a added to the event subscriber in the MV
Application.Current.Dispatcher.BeginInvoke(new Action CommandManager.InvalidateRequerySuggested));

EIASCII

How to write to a Boolean in EiASCII. Use >00 for False and >01 for True