How to use namespaces in XAML WPF including to refer to a converter (maybe other code too)

Place in header part of file. My initial mistake was
    xmlns:local="clr-namespace:MyConverters
Should have been
    xmlns:local="clr-namespace:OneWay.WPF.MyConverters
Need to include the assembly, even if it is the same project.
In this code local gives the namespace a short name.

Next using the namespace in XAML

<Style.Resources>
    <local:ButtonCenterConverter x:Key=”DivideByTwo”></local:ButtonCenterConverter>
</Style.Resources>

How to do Animation in WPF

 

How to extract an animation to a resource by using style
Also How to perform a scale transform in XAML

<ResourceDictionary xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns
:x=”http://schemas.microsoft.com/winfx/2006/xaml”&gt;

<Style TargetType=”Button”>
<Style.Triggers>
<EventTrigger RoutedEvent=”Button.MouseEnter”>
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty=”(RenderTransform).ScaleTransform.ScaleX)” To=”1.1″ Duration=”0:0:0.15″ />
<!–AutoReverse=”True” RepeatBehavior=”2x”–>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleY)” To=”1.1″ Duration=”0:0:0.15″ />

<!–<DoubleAnimation

Storyboard.TargetName=”GrowingButton”
Storyboard.TargetProperty=”Button.Height” To=”80″ Duration=”0:0:0.2″ />–>

</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent=”Button.MouseLeave”>
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleX)” To=”1.0″Duration=”0:0:0.15″ />

<!–AutoReverse=”True” RepeatBehavior=”2x”–></Storyboard></BeginStoryboard>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleY)” To=”1.0″ Duration=”0:0:0.15″ />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
<Setter Property=”RenderTransform”>
<Setter.Value>
<ScaleTransform
ScaleX=”1″ ScaleY=”1″
CenterX=”50″CenterY=”10″
/>
<!–CenterX=”{Binding Path=ActualWidth, ElementName=Button,Converter=}”–>
</Setter.Value>
</Setter>
</Style>
 

How to override a global style

Use Style=”{x:Null}”

How to perform a procedurally animated growing buttons using a scale transform

See Wrox VB2010 p214

How to perform XAML animation: First Success

             <Button Content=”Load” HorizontalAlignment=”Left” Name=”LoadButton” VerticalAlignment=”Top” Width=”75″ >
                <Button.Triggers>
                    <EventTrigger RoutedEvent=”Button.MouseEnter”>
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName=”LoadButton”
                                        Storyboard.TargetProperty=”Opacity” From=”1.0″ To=”0.0″ Duration=”0:0:1″ AutoReverse=”True” RepeatBehavior=”Forever” />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </Button.Triggers>
            </Button>

         <Button Content=”Growing” HorizontalAlignment=”Left” Margin=”479,4,0,0″ Name=”GrowingButton” VerticalAlignment=”Top” Width=”75″ >
            <Button.Triggers>
                <EventTrigger RoutedEvent=”Button.MouseEnter”>
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
                                        Storyboard.TargetName=”GrowingButton”
                                        Storyboard.TargetProperty=”Width” To=”80″ Duration=”0:0:0.5″ AutoReverse=”True” RepeatBehavior=”2x” />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Button.Triggers>
        </Button>>

How to use Application.Resources and also ResourceDictionaries in WPF

Application.Resources

The help page in MSDN is at:

http://msdn.microsoft.com/en-us/library/ms746624.aspx?lc=1033

I originally got this wrong, by trying to create a new Resource dictionary and placing the XAML <Application.Resources> into this new file.
When you create a new WPF application, an Application.xaml file is created automatically. This already contains an <Application.Resources> section, so just add in your new resources direct into here.

How to use Resource Dictionaries

Create Resource Dictionary, possibly putting it in a different folder, perhaps named Assets.
Then in Application.xaml

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”Assets\Dictionary1.xaml” />
<ResourceDictionary Source=”Assets\Dictionary2.xaml” />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
</Application.Resources>

<–Seem to be only able use Resoure Dictionary or Application.Resources not a mix of both
So Following line is invalid, because of following ResourceDictionaries
May be possible if a Key is used somewhere>–>
<!–<Brush x:Key=”myColorYellow”>Yellow</Brush>–>

Error 1

If on a window or page and “The designer does not support loading dictionaries that mix “ResourceDictionary” items without a key and other items in the same collection”

Solution 1:

Put the other resources inside the ResourceDictionary even if they are designed there.

With thanks to http://stackoverflow.com/questions/3818000/how-to-define-resources-and-a-mergedictionary-with-a-key-in-a-sl4-page

How to store Resource Dictionaries in a separate assembly and use them

In the following example of use. RDL01 is an external assembly. The word “component” is there as seen here.

<StackPanel>
<StackPanel.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”/RDL01;component/Dictionary1.xaml”></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</StackPanel.Resources>
<Button Content=”Hello” Width=”100″ Height=”50″></Button>
</StackPanel>

How to use the Property Windows for controls to use and extract Resources

Use extract value to resource

Dataset TableAdapter CommandTimeout

If get error:
“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding”

Setting the connection string timeout does not work.

Following links led me to my own visual basic translation. I found i had to add the check for the commandCollection Is Nothing
http://www.velocityreviews.com/forums/t123478-how-to-set-commandtimeout-for-getdata-method-of-tableadapter-asp-net-2-0-a.html
http://www.pcreview.co.uk/forums/tableadapter-and-commandtimeout-t2354775.html

Because the DatasetName.Designer.vb is a partial class, it is possible to create a second partial class which will not be overwritten on changes to the dataset. Remember to use

Namespace xxxTableAdapters

    Partial Public Class xxxTableAdapter

        Public WriteOnly Property SetSelectCommandTimeout() As Integer
            Set(ByVal value As Integer)
                If Me._commandCollection Is Nothing Then
                    Me.InitCommandCollection()
                End If
                Me.CommandCollection(0).CommandTimeout = value
                ‘For Each cmd In Me._commandCollection  ‘To do all
                ‘    cmd.CommandTimeout = value
                ‘Next
            End Set
        End Property

    End Class

End Namespace

Connect to VS-TFS remotely

This is another great help. Benefits include working more towards a common code library from home or work.

  • Connect to VPN
  • Visual Studio
    • > Connect to Team Foundation Server
    • Servers
    • Add
    • Use remote network internal i.p address
    • Use default settings
    • May be prompted for Login and password
    • Done > Success
  • Or in intenet explorer
    • http:// < internal ip address : <vs-tfs port number default = 8080> /tfs

Code Generation and T4 Text Templates

http://msdn.microsoft.com/en-us/library/bb126445.aspx

http://brochure.jrcs3.com/2011/03/t4-template-tour-of-first-gear.html

Include directive

Quite useful
<#@ include file=”TextTemplateVB6.t4″ #>
<#@ include File=”$(SolutionDir)\CodeDBGenerator\TextTemplateLibrary\TextTemplate\GeneratedHeader.t4″ #>

This uses actual file location, which may be different to how it appears in Solution explorer.

Note: the included file cannot have a <#@ template language=”VB” #> on it.
Probably want to rename it .t4 and remove the custom tool, so that it does not generate it’s own file.
After it has been included then Class Feature Blocks may be put in here for re-use by many templates. <#+

If you want it separately and also included elsewhere then a strategy I came up with was to have have the file without the <#@ template language=”VB” #> and then a separate file which was just:

<#@ template language=”VB” #>
<#@ include file=”TextTemplateVB6.t4″ #>
Be careful on .t4 file, you probably want to not have a custom tool. This can be done by creating a standard text file and changing it’s file extenstion to .t4 or create a text template file and then remove the Custom Tool from files properties. See:  Run Custom Tool

 

To use T4 within a program

To have a form that generates code say in a text box. Then:

  1. Set “Custom Tool” of text template to “TextTemplatingFilePreprocessor” and Custom Tool Namespace to say “My.Templates”
  2. Dim code = New My.Templates.PreTextTemplate1
    GeneratedCodeTextBox.Text = code.TransformText

 

To use If.

For instance with include file then:

<# If ParameterList(4) = 1 Then #>
<#@ include file=”SetRowBase.tt” #>
<# End If #>

 

More blog TODO

… looks potentially useful in some circumstances

Directives
http://msdn.microsoft.com/en-us/library/bb126421.aspx

To read
http://msdn.microsoft.com/en-us/library/gg251243.aspx

Run Custom Tool

Solution Folder > Point at file > Right click Properties
Custom Tool – Add or remove a custom tool name here.

Examples

  • TextTemplatingFileGenerator
  • TextTemplatingFilePreprocessor

‘Settings’ is not a member of ‘My’

SOLVED

Try adding the namespace, so:

My.Settings.conAName
becomes
[Namespace].Settings.conAName

Microsoft.Common.targets (1360): Found conflicts between different versions of the same dependent assembly

Problem

Warning : “Found conflicts between different versions of the same dependent assembly”

Not enough information

Solution – Method

The verbosity of builds may be changed in Visual Studio > Tools > Options > Projects and Solutions > Build and Run > MSBuild Project output verbosity. May need to go to at least detailed. Then use the output window to get more information.
The verbosity may also be changed in the VS-TFS build.

Then search in the Output for “conflict”, and underneath it states:

“References which depend on “… new version
“References which depend on “… old version

Make them match.

Solution – Binding Redirect

Optionally check-in the file containing the app.config.

If you double click on the warning then you may get a message:

“One or more dependent assemblies have version conflicts.
Do you want to fix these conflicts by adding binding redirect records in the app.config file?”

If you click OK, then use source code control to compare the app.config you will get a change in the newVersion setting

<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”EntityFramework” publicKeyToken=”B77A5C561934E089″ culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-4.4.0.0″ newVersion=”6.0.0.0″ />
</dependentAssembly>
</assemblyBinding>
</runtime>

This Post History

VS-TFS Build was reporting this error for a long time, but not indicating precisely which file was causing the problem

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1360): Found conflicts between different versions of the same dependent assembly

Generally have found the problem to be on a project which references another project, where both projects use the same references. One may get out of sync with the project being built.

Found the problem difficult to find. Not entirely sure what the problem was:
The build server had a copy of version 9 of Microsoft.VisualBasic.PowerPacks.Vs in c:\Program Files\Common Files\Microsoft Shared\…
instead of version 10.0 listed in some projects.
I checked that version 10 was installed on the build server, then removed the version 9 from this pc.
Could have perhaps considered making the PowerPack reference copy local.

Also try working out any references listed in the problem project which are also used by referenced projects and include a reference to the problem project. I have found that where Visual Studio builds projects without the referenced project references, MSBuild seems to need them in the target project as well. This was not in fact the case in my resolution here.

Example solved 15-Mar-2011 was System.Windows.Forms.DataVisualization was version 3.5.0.0 in a user control. Upgraded all to 4.0.0.0.

See http://stackoverflow.com/questions/1871073/resolving-msb3247-found-conflicts-between-different-versions-of-the-same-depend

How do I … work with Guid in ADO.Net?

How do I … work with Guid in ADO.Net?
( in this case to support SQL Server replication using dataset )

26-Dec-2011
Hypothesis: That DataSet could act unaware of replication column (do not import it on datatable creation) (or delete it after). Then use default in SQL Server (newsequentialid())
Experiment: Worked out of the box – straight away

During creation of SQL Replication, SQL Server will add a rowGuid column which is a uniqueidentifier and places a default of (newsequentialid()) onto this column
Insert statements for replication must include all columns, except the rowGuid column.

ERROR
However if you then add a new row to this table in ADO.Net then program will give error message ‘Column rowGuid does not allow nulls’

SOLUTION
[MyDataTable].rowguidColumn.DefaultValue = Guid.NewGuid

EXPLANATION
SQL will have inserted a Unique index on rowGuid. However when the table is dropped onto the dataset the unique key is not there. Therefore although the above default set once will give each new row the same Guid, the ADO.net sees no errors. Because the insert statement does not insert the Guid, SQL does, then ADO.Net immediately returns the correct newly applied Guid from the database. This is because the Dataset insert statement also has a SELECT statement on it to get table updates immediately after the INSERT.

SQL Server Replication

Updating ERROR
Updating columns with the rowguidcol property is not allowed.
The transaction ended in the trigger. The batch has been aborted.

Removed the rowguid column from the dataset update sql and it worked. Found no online instruction for this in short search.