LEGO® SEGWAY
LEGO® MINDSTORMS(tm) Internals
Wikipedia Mindstorm
Mindstorm Sensors etc
Thursday, 18 February 2010
Wednesday, 17 February 2010
SILVERLIGHT
Encountered problems with cross threading when binding a USerName property in a Singleton class using WCF.
The UserName property in the singleton is updated using a BeginGetUserName WCF method with a EndGetUserName and this caused a cross thread exception because the UserName was being updated outside the UI thread. Solution was to pass a dispatcher object into the Singleton from MainPAge code behind and then use a BeginInvoke method to update the Username in the EndGetUserName method. Hence :
private void GetUserName()
{
Svc.BeginGetUserName(new AsyncCallback(GetUserNameCallback), Svc);
}
private void GetUserNameCallback(IAsyncResult ar)
{
IDriveParameterService s = (IDriveParameterService)ar.AsyncState;
dispatcher.BeginInvoke(delegate()
{
UserName = s.EndGetUserName(ar);
}
);
}
The UserName property in the singleton is updated using a BeginGetUserName WCF method with a EndGetUserName and this caused a cross thread exception because the UserName was being updated outside the UI thread. Solution was to pass a dispatcher object into the Singleton from MainPAge code behind and then use a BeginInvoke method to update the Username in the EndGetUserName method. Hence :
private void GetUserName()
{
Svc.BeginGetUserName(new AsyncCallback(GetUserNameCallback), Svc);
}
private void GetUserNameCallback(IAsyncResult ar)
{
IDriveParameterService s = (IDriveParameterService)ar.AsyncState;
dispatcher.BeginInvoke(delegate()
{
UserName = s.EndGetUserName(ar);
}
);
}
WCF
When hosting a WCF service in an Asp.Net application it is possible to get to the
HttpContext.Current to access the User.Identity.Name as follows:
1. Add serviceHostingEnvironment aspNetCompatibilityEnabled="true" to the web.config
2. Add [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
to the service implementation.
HttpContext.Current to access the User.Identity.Name as follows:
1. Add serviceHostingEnvironment aspNetCompatibilityEnabled="true" to the web.config
2. Add [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
to the service implementation.
Friday, 12 February 2010
Wednesday, 3 February 2010
Monday, 1 February 2010
WPF DIAGRAMMING : DataTemplate ing
Using the superb WPF Diagram Designer by sukram on CodeProject.
Trying to taylor the code to my own use. In particular been trying to specify a Xaml DataTemplate for the ToolBoxItem which is a custom control based on ContentControl.
Inside the ToolBox which is itself a custom control based on the ItemsControl when I specify a ItemTemplate and point it at my DataTemplate it fails. Found I needed to add a ContentTemplate to the style and make it a TemplateBinding to the ContentControl.ContentTemplate, hence
<Style TargetType="{x:Type cc:ToolboxItem}">
<Setter Property="Control.Padding" Value="5" />
<Setter Property="ContentControl.HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContentControl.VerticalContentAlignment" Value="Stretch" />
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:ToolboxItem}">
<Grid>
<Rectangle Name="Border" StrokeThickness="1" StrokeDashArray="2" Fill="Transparent"
SnapsToDevicePixels="true" />
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Stroke" Value="Gray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
then I can specify the DataTemplate inside my ToolBox (ItemsControl) using ItemTemplate="{StaticResource designItemDataTemplate}"
Trying to taylor the code to my own use. In particular been trying to specify a Xaml DataTemplate for the ToolBoxItem which is a custom control based on ContentControl.
Inside the ToolBox which is itself a custom control based on the ItemsControl when I specify a ItemTemplate and point it at my DataTemplate it fails. Found I needed to add a ContentTemplate to the style and make it a TemplateBinding to the ContentControl.ContentTemplate, hence
<Style TargetType="{x:Type cc:ToolboxItem}">
<Setter Property="Control.Padding" Value="5" />
<Setter Property="ContentControl.HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContentControl.VerticalContentAlignment" Value="Stretch" />
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:ToolboxItem}">
<Grid>
<Rectangle Name="Border" StrokeThickness="1" StrokeDashArray="2" Fill="Transparent"
SnapsToDevicePixels="true" />
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Stroke" Value="Gray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
then I can specify the DataTemplate inside my ToolBox (ItemsControl) using ItemTemplate="{StaticResource designItemDataTemplate}"
Subscribe to:
Posts (Atom)