понедельник, 5 декабря 2011 г.

WPF LinkButton



Add style to resources of the UserControl, where the (link)button is situated:

    <Style x:Key="LinkButton"
       TargetType="Button"
       BasedOn="{StaticResource ResourceKey={x:Type Button}}">
            <Setter Property="Width" Value="Auto"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter Content="{TemplateBinding Content}"
                                  ContentTemplate="{TemplateBinding  ContentTemplate}"
                                  VerticalAlignment="Center">
                            <ContentPresenter.Resources>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="TextDecorations" Value="Underline" />
                                </Style>
                            </ContentPresenter.Resources>
                        </ContentPresenter>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>

Set style in code:

var button = new Button() {Style = (Style)(this.Resources["LinkButton"])};

Or in XAML:

Style={StaticResources LinkButton}

среда, 24 августа 2011 г.

How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))


How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))

First you need create instance of VersionControlServer object. Then use CreateBranchObject method. serverTrunkPath="C:\myWorkspace\trunk" - target folder you want to make branch.

versionControlServer.CreateBranchObject(new BranchProperties(new ItemIdentifier(serverTrunkPath)));

вторник, 10 мая 2011 г.

Working Example of Web.config for WCF-Service IIS hosted for Silverlight with Windows Authentication


<?xml version="1.0" encoding="UTF-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <customErrors mode="RemoteOnly" />
        <authentication mode="Windows" />
      </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <services>
            <service name="web4.TsService">
              <endpoint address="" binding="basicHttpBinding" bindingConfiguration="web4.TsService.customBinding0" contract="web4.TsService">
                  <identity>
                    <dns value="MyDomainName" />
                  </identity>
                  </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
              <host>
                <baseAddresses>
                  <add baseAddress="http://MyServerName.MyDomainName:8080/tfs/web4/"/>
                </baseAddresses>
              </host>
            </service>
        </services>
        <bindings>
            <basicHttpBinding>
                <binding name="web4.TsService.customBinding0">
                  <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm"></transport>
                  </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client />
    </system.serviceModel>
</configuration>

среда, 4 мая 2011 г.

Silverlight 3 HierarchicalDataTemplate


I was able to get it work!

1) First treaky thing : You must find where HierarchicalDataTemplate is living
xmlns:xctrl="clr-namespace:System.Windows;assembly=System.Windows.Controls"

2) In silverlight you should explicitly point thе template. While in WPF the way you move is type recognition in hierarhy. There is DataType property for HierarchicalDataTemplate in WPF.
Here in silverlight ItemTemplate for ChildTemplate. For child use DataTemplate or HierarhicalDataTemplate




<UserControl x:Class="TestSilverlight5.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:xctrl="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    mc:Ignorable="d"
    d:DesignHeight="337" d:DesignWidth="591" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Loaded="UserControl_Loaded">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <xctrl:HierarchicalDataTemplate x:Key="ChildTemplate">
                <CheckBox Content="{Binding Path=Name}"  IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"></CheckBox>
            </xctrl:HierarchicalDataTemplate>
            <xctrl:HierarchicalDataTemplate x:Key="ParentTemplate" ItemsSource="{Binding Path=Users, Mode=TwoWay}" ItemTemplate="{StaticResource ChildTemplate}">
                <CheckBox FontStyle="Italic" Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"></CheckBox>
            </xctrl:HierarchicalDataTemplate>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="12" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <data:DataGrid AutoGenerateColumns="False" Name="dataGrid1" Grid.Column="2">
            <data:DataGrid.Columns>
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
            </data:DataGrid.Columns>
        </data:DataGrid>
        <controls:GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="0" Name="gridSplitter1" Width="12" Cursor="SizeWE">
            <controls:GridSplitter.Background>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="#FFBCF1F1" Offset="0" />
                    <GradientStop Color="#FFC8CDCD" Offset="1" />
                    <GradientStop Color="#FFEBFBFB" Offset="0.325" />
                    <GradientStop Color="#FFA3B3B3" Offset="0.797" />
                </LinearGradientBrush>
            </controls:GridSplitter.Background>
        </controls:GridSplitter>
        <Button Content="View" HorizontalAlignment="Left" Margin="7,0,0,5" Name="buttonView" Width="65" Height="23" VerticalAlignment="Bottom" />
        <controls:TreeView Name="treeView" ItemTemplate="{StaticResource ParentTemplate}">

        </controls:TreeView>
    </Grid>
</UserControl>

вторник, 22 марта 2011 г.

Select filename from file path


To get file name from file path by Regex:

string file = Regex.Match(FilePath, @"(?<=([\\/]))([^\\/])*?$").Value;

Example:
FilePath="/UI/Pages/WorkItems/QueryExplorer.aspx"
file="QueryExplorer.aspx"

четверг, 10 февраля 2011 г.

Convert files from Dos to Unix and back.


        private void Unix2Dos(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] DOS_LINE_ENDING = new byte[] { CR, LF };
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, LF, position);
                    if (index >= 0)
                    {
                        if ( ( index > 0 ) && (data[index - 1] == CR ))
                        {
                            // already dos ending
                            bw.Write(data, position, index - position + 1);
                        }
                        else
                        {
                            bw.Write(data, position, index - position);
                            bw.Write(DOS_LINE_ENDING);
                        }
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
               fileStream.SetLength(fileStream.Position);
            }
        }

        private void Dos2Unix(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, CR, position);
                    if ((index >= 0) && (data[index + 1] == LF))
                    {
                        // Write before the CR
                        bw.Write(data, position, index - position);
                        // from LF
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
                fileStream.SetLength(fileStream.Position);
            }
        }