Syntax Error

Code samples and hints

Scrollable TextBox for Windows Phone

The TextBox control does not support scrolling in the non-edit mode.

If needed, there is the simple way:
http://forums.create.msdn.com/forums/p/69286/430208.aspx

Or you can create your own ControlTemplate and do something like this:

 

<ControlTemplate x:Key="ScrollableTextBox" TargetType="TextBox">
	<Grid Background="Transparent">
		<VisualStateManager.VisualStateGroups>
[...]
			<VisualStateGroup x:Name="FocusStates">
				<VisualState x:Name="Focused">
					<Storyboard>
[...]
						<ObjectAnimationUsingKeyFrames Storyboard.TargetName="EnabledBorderScroll" Storyboard.TargetProperty="VerticalScrollBarVisibility">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<ScrollBarVisibility>Disabled</ScrollBarVisibility>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
		<Border x:Name="EnabledBorder" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Margin="{StaticResource PhoneTouchTargetOverhang}">
			<ScrollViewer x:Name="EnabledBorderScroll" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
				<ContentControl x:Name="ContentElement" BorderThickness="0" Padding="{TemplateBinding Padding}" 
				HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}"/>
			</ScrollViewer>
		</Border>
		<Border x:Name="DisabledOrReadonlyBorder" Visibility="Collapsed" Background="Transparent" BorderBrush="{StaticResource PhoneDisabledBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="{StaticResource PhoneTouchTargetOverhang}" >
			<TextBox x:Name="DisabledOrReadonlyContent" Text="{TemplateBinding Text}" Foreground="{StaticResource PhoneDisabledBrush}" Background="Transparent"
				SelectionBackground="{TemplateBinding SelectionBackground}" SelectionForeground="{TemplateBinding SelectionForeground}"
				TextWrapping="{TemplateBinding TextWrapping}" TextAlignment="{TemplateBinding TextAlignment}" IsReadOnly="True" Template="{StaticResource PhoneDisabledTextBoxTemplate}"
				FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" />
		</Border>
	</Grid>
</ControlTemplate>

Mouse without Borders

Mouse Without Borders is a project I’ve been familiar with for the last 6 months or so and it’s a wonderfully useful tool. In a nutshell, it allows you to reach across your PC's as if they were part of one single desktop. I have two PCs on my desk at work connected to 3 LCD screens and using Mouse Without Borders I can move my mouse between the 3 screens, even though one of them is attached to a different PC from the other two. What’s more, I can move files between the 2 computers simply by dragging them from one desktop to another. In fact you can control up to four computers from a single mouse and keyboard with no extra hardware needed – it’s all software magic, developed by Truong Do who by day is a developed for Microsoft Dynamics. The software is easy to setup and in addition to enabling drag and drop of files, you can lock or log in to all PCs from one PC, and as a whimsical bonus is it allows you to customize your Windows logo screen with the daily image from Bing or a local collection of pictures :) I regularly use it to have one PC dedicated to social media streams while I work away on my other PC connected to two screens.

Read the full blog at blogs.technet.com

 

 

‘Cannot register duplicate name ‘XXX’ in this scope’ in VS 2010

If you have the problem, that Visual Studio 2010 complains ‘Cannot register duplicate name ‘XXX’ in this scope’, check if you have Resources with a x:Name insted of x:Key-Name:

<SolidColorBrush x:Name="NonWorkingResourceName" Color="Red" />
<SolidColorBrush x:Key="WorkingResourceName" Color="Blue" />

Replace x:Name with x:Key and everything is ok.

Read the full post here ...

Caliburn.Micro – Introduction

Caliburn.Micro – Introduction

Caliburn.Micro is a lightweight and small, yet powerful framework for developing rich WPF, Silverlight or Windows Phone applications. Caliburn.Micro has only a single dependency to the System.Windows.Interactivity library. Due to its small footprint of only 75 k and approximately 2700 lines of code it is not only lightning fast in startup and execution time but also easy to understand. The framework offers pattern guidance for the following well established design patterns:

  • Model – View – ViewModel (MVVM)
  • Model – View – Presenter (MVP)
  • Model – View – Controller (MVC)

Rob Eisenberg (www.robeisenberg.com) and Marco Amendola (marcoamendola.wordpress.com) are actively maintaining the project and taking care of the documentation. The documentation is really thorough and offers tips and tricks how to avoid the common pitfalls. The project is released under a developer and company friendly license namely the MIT License.

http://www.bbv.ch/?p=450&option=com_wordpress&Itemid=173

Change Database-Table Collations

To change the Database Table Collations dynamically, you can generate update scripts with the following snippet

declare  @toCollation sysname 
      
SET    @toCollation = 'Latin1_General_100_CI_AS' --  << insert your destination collation name

SELECT 'ALTER TABLE ' + INFORMATION_SCHEMA.COLUMNS.TABLE_NAME +
       '   ALTER COLUMN ' + COLUMN_NAME + ' ' + DATA_TYPE +
       CASE WHEN CHARACTER_MAXIMUM_LENGTH = -1 then '(max)'
            WHEN DATA_TYPE in ('text','ntext') then ''
            WHEN CHARACTER_MAXIMUM_LENGTH IS NOT NULL 
             THEN '('+(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH)+')' )
            ELSE isnull(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH),' ') END
       +' COLLATE ' + @toCollation+ ' ' + CASE IS_NULLABLE
                                           WHEN 'YES' THEN 'NULL'
                                           WHEN 'No' THEN 'NOT NULL' 

END
FROM INFORMATION_SCHEMA.COLUMNS INNER JOIN INFORMATION_SCHEMA.TABLES
ON  INFORMATION_SCHEMA.COLUMNS.TABLE_NAME = INFORMATION_SCHEMA.TABLES.TABLE_NAME
AND INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA  = INFORMATION_SCHEMA.TABLES.TABLE_SCHEMA
WHERE DATA_TYPE IN ('varchar' ,'char','nvarchar','nchar','text','ntext')
AND TABLE_TYPE = 'BASE TABLE'
and COLLATION_NAME <> @toCollation

Solution: It takes much longer to run a stored procedure than run the code inside the stored procedure

If you have the problem that a stored procedure takes much longer to execute than the exactly same code direct on the MS SQL Server Management Studio, consider the possibility of side-effects from "Parameter Sniffing".
 
Example:
CREATE Procedure [dbo].[SlowExcecution]
@MyParam NVARCHAR(50)
AS

SELECT * FROM XYZ WHERE A = @MyParam
GO
 
If this code runs fast without SP, but slow as SP, then add a new local variable and copy the parameter into this variable. Then use this variable instead of the parameter.
CREATE Procedure [dbo].[FastExcecution]
@MyParam NVARCHAR(50)
AS

DECLARE @MyLocalVariable NVARCHAR(50)
@MyLocalVariable = @MyParam

SELECT * FROM XYZ WHERE A = @MyLocalVariable
GO
 
For details and background informations take a look at this great blog ....