Pages

Friday, 22 April 2011

jQuery Callbacks

A recent foray into jQuery land left me floundering with the callback syntax.

$("#datepicker").datepicker(
{
// The CallBack argument is an anonymous function
onSelect: function(dateText, inst)
{
// This invokes the real function
myCallBackFunction(dateText, inst);
}
}
);

// This is the real function that will
// be executed when the onSelect
// invokes its Callback
function myCallBackFunction(dateText,inst)
{
$("#selectedDate").val(dateText);
}

With a simple callback function the anonymous function can contain the processing.


$("#datepicker").datepicker(
{
// The CallBack argument is an anonymous function
onSelect: function(dateText, inst)
{
$("#selectedDate").val(dateText);
}
}
);

Saturday, 12 March 2011

ResourceStrings Access Modifier

When a new Resource file is added to a project the Access Modifier defaults to Internal.

There is a small combobox at the top of the Resource editor that allows it to be changed.

Thursday, 10 March 2011

COM Data Types

Data type conversions from COM to .Net
























IDL Type.NET Type
charSystem.SByte
shortSystem.Int16
int, long, HRESULT and SCODESystem.Int32
int64System.Int64
unsigned charSystem.Byte
unsigned shortSystem.UInt16
unsigned int and unsigned longSystem.UInt32
uint64System.UInt64
floatSystem.Single
doubleSystem.Double
BSTR, LPSTR and LPWSTRSystem.String
VARIANT_BOOLSystem.Boolean
DATESystem.DateTime
GUIDSystem.Guid
DECIMALSystem.Decimal
CURRENCYSystem.Decimal
VARIANTSystem.Object
IUnknown*System.Object
IDispatch*System.Object
void*System.IntPtr
IDispatchEx*System.Runtime.InteropServices.Expando.IExpando
IEnumVariant*System.Collections.IEnumerator










COMIDL
boolean and smallchar
wchar_tunsigned short
hyper and __int64int64
[string] char*LPSTR
[string] wchar_t*LPWSTR
byteunsigned char
unsigned hyper and unsigned __int64uint64

Wednesday, 16 February 2011

MouseOver Triggers

Here is a minimal example of changing the background colour of a TextBlock when MouseOver is detected.
<Window.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Pink" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock>Hello World</TextBlock>
</StackPanel>

Tuesday, 18 January 2011

Moving down a cell in a datagrid when you press Enter

In Stock we have some DataGrids for things like Counts, which we want to be able to enter values for successive rows from the keyboard.. ie, 1 , 3 etc..

While Tab moves across a cell, Enter doesn’t move the cell focus (since we’re using a custom control of a textbox in there, the textbox swallows the enter).

To enable the Enter to work, you can just add a KeyDown handler for the TextBox in the template and then add this code behind :
      private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Key == Key.Enter) || (e.Key == Key.Return))
{
TextBox FocusedControl = Keyboard.FocusedElement as TextBox;

if (FocusedControl != null)
{
TraversalRequest Traversal = new TraversalRequest(FocusNavigationDirection.Down);

FocusedControl.MoveFocus(Traversal);
}
}
}
Nice and simple in the end --- it turns out that the TraversalRequest and FocusNavigationDirection classes/enums are very simple and powerful & not limited to DataGrids at all.

Monday, 10 January 2011

ResourceStrings in XAML

I needed to replace some hard-coded text in the xaml templates used in our Till Roll control. There was no easy route through to a general ViewModel that could expose some relevant properties to bind to.
In the end I chose to bind directly to the ResourceStrings resource using an x:Static
...
xmlns:local="clr-namespace:Sandstorm.PointOfSale.Modules.Tender.Resources"
...
<TextBlock Padding="20,0,0,0" Text="{Binding Source={x:Static local:ResourceStrings.V_Discount}, Mode=OneTime}" FontStyle="Italic"/>

Wednesday, 8 December 2010

EditorBrowsable

The EditorBrowsableAttribute class specifies whether a property or method is viewable via Intellisense.
It is used like this:

using System.ComponentModel;
...
[EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
protected void AdvancedMethod()
{
//The property or method is a feature that only advanced users should see. An editor can either show or hide such properties
}
[EditorBrowsableAttribute(EditorBrowsableState.Always)]
protected void AlwaysMethod()
{
//The property or method is always browsable from within an editor
}
[EditorBrowsableAttribute(EditorBrowsableState.Never)]
protected void NeverMethod()
{
//The property or method is never browsable from within an editor
}
I wanted to use it with a class that provided a fluent interface to hide the common methods like Equals, GetHashCode, GetType, ToString etc. to make the fluent interface syntax cleaner.
It transpires that it is only used by Intellisense when the decorated item is in a referenced assembly - shame.
Here is the fuller explanation from Linda Lui, Microsoft Online Community Support back in June 2006:

Speaking for C#, the EditorBrowsableAttribute attribute only influences C#
IntelliSense filtering behavior if the decorated item is imported from
metadata.
That's to say, you should compile the EditorBrowsableAttribute-decorated
project(e.g project 1) into an assembly(.dll or .exe) and then in another
project(e.g project 2) add a reference to that assembly. In project 2, you
should see the attribute at work.
C# IntelliSense filtering behavior is not influenced if you are coding in
project 1. What's more, if you add a project-to-project reference to
project 1 in project 2, C# IntelliSense filtering behavior is not
influenced when you are coding in project 2 either.
The IDE is intended to filter items from consumers of your assembly and not
to filter items from yourself as you code the assembly.