Showing posts with label wpf. Show all posts
Showing posts with label wpf. Show all posts

Multiple CustomActionData fields

Posted by senthil | 8:02:00 AM | , , | 0 comments »

This is multiple CustomActionData field pass in SetUp  file.

 it is possible to add one or more custom screens in the setup wizard, with fields (e.g. text boxes) where the user can enter additional installation parameters.
A custom field can then be passed to a "Custom Action" class library project, to handle the user field. The image below shows how the property "ServerName" gets mapped to the EDITB1 text field:


Within the Custom Action class, the property is accessed as follows:
string targetdir = Context.Parameters["TARGETDIR"];
string stationname = Context.Parameters["STATIONNAME"];
string facility = Context.Parameters["FACILITY"];
string line = Context.Parameters["Line"];
string email = Context.Parameters["Email"];
string environment = Context.Parameters["ENVIRONMENT"];
/TARGETDIR="[TARGETDIR]\" /STATIONNAME="[STATIONNAME]" /FACILITY="[FACILITY]" /LINE="[LINE]" /EMAIL="[EMAIL]" /ENV="[ENVIRONMENT]"
Read more ...

This code create a new roundedbutton for wpf application.

Its easy understand and customes button style. I want to create rounded button for in my application and style effect change when Button Enable and Disable time after that IsEnable time when i click the button that style change like a normal button.

Here i used in Gradient color also we can customes


<Button Command="Print" Name="butSinglePrint" Height="40" Width="40" Margin="6">
        <Button.Template>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <Ellipse 
                         StrokeThickness="2">
                        <Ellipse.Fill>
                            <RadialGradientBrush GradientOrigin="0.496,1.052">
                                <RadialGradientBrush.RelativeTransform>
                                    <TransformGroup>
                                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
                                        <TranslateTransform X="0.02" Y="0.2"/>
                                    </TransformGroup>
                                </RadialGradientBrush.RelativeTransform>
                                <GradientStop Offset="1" Color="Green"/>
                                <GradientStop Offset="0.2" Color="Green"/>
                            </RadialGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>                    
                    <Ellipse Margin="3" Name="highlightCircle">
                        <Ellipse.Fill >
                                                <LinearGradientBrush>
                                                    <GradientStop Offset="0" Color="#50FFFFFF"/>
                                                    <GradientStop Offset="0.5" Color="#00FFFFFF"/>
                                                    <GradientStop Offset="1" Color="#50FFFFFF"/>
                                                </LinearGradientBrush>
                                            </Ellipse.Fill>
                    </Ellipse>
                    <Ellipse Name="disableCircle" >
                        <Ellipse.Fill>
                                                <LinearGradientBrush >
                                                    <GradientStop Offset="0" Color="#50FFFFFF"/>
                                                    <GradientStop Offset="0.5" Color="#00FFFFFF"/>
                                                    <GradientStop Offset="1" Color="#50FFFFFF"/>
                                                </LinearGradientBrush>
                                            </Ellipse.Fill>
                    </Ellipse>
                    <Border Name="highlightBorder"  BorderBrush="#002A00" CornerRadius="18" BorderThickness="0,0,1,1">
                        <ContentPresenter HorizontalAlignment="Center"
                                  VerticalAlignment="Center"/>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="highlightBorder"  Property="FocusVisualStyle" Value="{x:Null}"/>
                        <Setter TargetName="highlightBorder"  Property="BorderThickness" Value="1,1,0,0" />
                        <Setter TargetName="highlightBorder"  Property="BorderBrush" Value="#002A00" />                       
                        <Setter TargetName="highlightCircle" Property="Fill">
                                                <Setter.Value>
                                                    <LinearGradientBrush StartPoint="0.3,0" EndPoint="0.4,1">
                                                    <GradientStop Offset="0" Color="#50FFFFFF"/>
                                                    <GradientStop Offset="0.5" Color="#00FFFFFF"/>
                                                    <GradientStop Offset="1" Color="#50FFFFFF"/>
                                                </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="disableCircle" Property="Fill">
                            <Setter.Value>
                                <LinearGradientBrush StartPoint="0.6,0" EndPoint="1.4,1">
                                    <GradientStop Offset="0" Color="#C3C8C9"/>
                                    <GradientStop Offset="0.5" Color="#CFD3D4"/>
                                    <GradientStop Offset="2" Color="#9A9FA1"/>
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="True">
                        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                        <Setter TargetName="highlightBorder"  Property="BorderThickness" Value="1,1,1,1" />
                                        <Setter TargetName="highlightBorder" Property="BorderBrush">
                                            <Setter.Value>
                                                <LinearGradientBrush StartPoint="0.6,0" EndPoint="1.4,1">
                                                    <GradientStop Offset="0" Color="#3FFF3F"/>
                                                    <GradientStop Offset="0" Color="#3FFF3F"/>
                                                    <GradientStop Offset="0.5" Color="#002A00"/>
                                                </LinearGradientBrush>
                                            </Setter.Value>
                                        </Setter>                  
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>
    </Button>
Read more ...

Sample Multi thread Functionality in C#

Posted by senthil | 6:43:00 PM | , | 0 comments »

this code sample main class i created multi thread concept. already i used thread in my application while call my method continuously but there is deadlock occurred because already different thread runing there so thats what i used multi thread like this.
using System; 
using System.Threading; 
public class Test { 
static void Main() { 
ThreadStart job = new ThreadStart(ThreadJob); 
Thread thread = new Thread(job); 
thread.Start();
 for (int i=0; i < 5; i++) { 
Console.WriteLine ("Main thread: {0}", i); 
Thread.Sleep(1000); 
}
 }
 static void ThreadJob() { 
for (int i=0; i < 10; i++) {
 Console.WriteLine ("Other thread: {0}", i); 
Thread.Sleep(500); 
}
}
 } 
Read more ...

I am working in wpf application. i want to call the print method till when i click stop button. So that case i have used in thread concept while i was getting This error 'The calling thread cannot access this object because a different thread owns it' because also multiple thread run in that method so i handled this type of solution. my print method called in PrintElement like this;
public static PrintLable PrintElement()
{
    PrintLable printLable= null;
    Application.Current.Dispatcher.Invoke(
       System.Windows.Threading.DispatcherPriority.Normal, new Action(
          delegate()
          {
              PrintElement printLable = new PrintElement();
              // Initialize your PrintElement here
          }));
    return printLable;
}
Read more ...

This is all the USB device read from your local machine using C#. I am working in wpf windows application. When i want to read my system USB Device i got this sample code. This code every easy to learn and implement as you want. just copy and past in your application.
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

  static void Main()
        {
            var usbDevices = GetUSBDevices();

            foreach (var usbDevice in usbDevices)
            {
                Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}",
                    usbDevice.DeviceID, usbDevice.PNPDevideID, usbDevice.Description);
            }

            Console.Read();
        }


        static List<USBDeviceInfo> GetUSBDevices()
        {
            List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

            ManagementObjectCollection collection;
            using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
                collection = searcher.Get();

            foreach (var device in collection)
            {
                devices.Add(new USBDeviceInfo(
                (string)device.GetPropertyValue("DeviceID"),
                (string)device.GetPropertyValue("PNPDeviceID"),
                (string)device.GetPropertyValue("Description")
                ));
            }

            collection.Dispose();
            return devices;
        }
    }

    class USBDeviceInfo
    {
        public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
        {
            this.DeviceID = deviceID;
            this.PNPDeviceID = pnpDeviceID;
            this.Description = description;
        }
        public string DeviceID { get; private set; }
        public string PNPDeviceID { get; private set; }
        public string Description { get; private set; }
    } 
Read more ...

LINQ using XML data load to combobox.

Posted by senthil | 8:40:00 PM | , , | 0 comments »

To use LINQ to XML you will need to import a two of namespaces.
using System.Linq;
using System.Xml.Linq;


private void StudentsLoad()
{
  var xElem = XElement.Load(@"Student.xml");

  var students = from prod in xElem.Descendants("Student")
           orderby prod.Element("StudentName").Value
           select prod.Element("StudentName").Value;

  lstStudents.DataContext = students;
}
Read more ...

When i want to xml data load to the combobox . i got this solution. Its very simple to load the xml data. this the xml data.
<Items>
  <Item>
    <ItemId>1</ItemId>
    <ItemName>Architecting ASP.NET Applications
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
  <Item>
    <ItemId>2</ItemId>
    <ItemName>Fundamentals of N-Tier eBook</ItemName>
    <Price>19.95</Price>
  </Item>
     ...
     ...
  <Item>
    <ItemId>3</ItemId>
    <ItemName>Security for ASP.NET Developers
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
</Items>
this is stackpanel resource load, it will load on window loaded
<StackPanel.Resources>
  <XmlDataProvider x:Key="ItemsData"
                   Source="/Items.xml"
                   XPath="Items/Item" />
</StackPanel.Resources>
Its a combobox wirte like this, i loaded in ItemName if you want price load to another one combobox just change the xPath and then automatically load the price data to the combobox.
<ComboBox Name="Items" MinWidth="200" Style="{StaticResource RequiredComboBox}" Foreground="Black" FontSize="30" IsSynchronizedWithCurrentItem="False" SelectedIndex="0">
                    <ComboBox.ItemContainerStyle>
                        <Style TargetType="ComboBoxItem">
                            <Setter Property="Padding" Value="5">
                            </Setter>
                        </Style>
                    </ComboBox.ItemContainerStyle>
                    <ComboBox.ItemsSource>
                        <Binding Source="{StaticResource ItemsData}" XPath="ItemName" />
                    </ComboBox.ItemsSource>
                </ComboBox>
Read more ...

I am working in wpf application when i want to open the child window from Parent window button click. that time i am getting this solution. Just write Parent window click event method like this.
private void Button_Click(object sender, RoutedEventArgs e)
        {            
            window2 win2= new window2();
            win2.Show();
            this.Close();
        }
Read more ...

This code create an round button in wpf application using ResourceDictionary. create an xaml file like this.
<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Style x:Key="RoundButtonTemplate" TargetType="Button">
        <Setter Property="Background" Value="Brown"/>
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border CornerRadius="15" Background="{TemplateBinding Background}"
                                BorderThickness="1">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">

                        </ContentPresenter>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
after that create and main window xaml file and then just call this RoundButtonTemplate style using Window.Resources load the GlassButton.xaml file and then call the StaticResource in main window like this.
<Window x:Class="GlassButton.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Glass Buttons" Height="228" Width="272">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\GlassButton.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
<Grid>
 <StackPanel Orientation="Horizontal">
<Button Focusable="False"
        Style="{StaticResource RoundButtonTemplate}"
        Width="264"
       Height="90" 
       Grid.Row="0"
       Margin="0,0,0,0"
       HorizontalAlignment="Center"
       BorderBrush="#FFF"
       Name="PasswordButton"
       Click="PasswordButton_Click"> 
                                             
 </Button>
  </StackPanel>
</Grid>
</Window>
Read more ...

This is code i have an exprience when i want to create a round button in my application i have used this code. this is one way of the create round button in wpf application. if we want change the color and Radial Gradient color and also we can able to apply the Transform using opacity. its very useful i have past the following code.
<Button Width="100" Height="100">
                <Button.Template>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <Ellipse Stroke="#5ECF5E"
                         StrokeThickness="2">
                                <Ellipse.Fill>
                                    <RadialGradientBrush GradientOrigin="0.496,1.052">
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
                                                <TranslateTransform X="0.02" Y="0.2"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Offset="1" Color="#5ECF5E"/>
                                        <GradientStop Offset="0.2" Color="#FFFFFFFF"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="Center"
                                  VerticalAlignment="Center"/>
                        </Grid>
                    </ControlTemplate>
                </Button.Template>
            </Button>
another one way to create the round button.
<Button  Width="100" Height="100" Content="Abcd">
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                <Ellipse Fill="Red"/>
                    <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Button.Template>
    </Button>
this code create an rectangle button with color and Radial Gradient color and also we can able to apply the Transform using opacity.
<UserControl x:Class="WindowsFormsApplication8.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="154" Width="177">
    <Grid>
        
        <Rectangle Name="rectangle1" Stroke="Black" RadiusX="10" RadiusY="10" >
        </Rectangle>
 
        <Button Name="rectangle2" Foreground="Black" Margin="3,3,3,3" >
            <Button.Background >
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="Green" Offset="0.0" />
                    <GradientStop Color="White" Offset="0.9" />
                </LinearGradientBrush>
            </Button.Background>
        </Button>
    </Grid>
</UserControl>
Read more ...

This code create a new gridview in wpf application. its working good.
<Grid>
        <DataGrid x:Name="MyDataGrid" x:Uid="MyDataGrid" AutoGenerateColumns="False" 
                       AlternationCount="2" SelectionMode="Single" Height="175" VerticalAlignment="Bottom" Background="White" Margin="12,0,12,12" CanUserAddRows="False" CanUserDeleteRows="False">
            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Name}"
                                    Header="Name" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Email}" 
                                    Header="Email" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=DOB}"
                                    Header="DOB" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Address1}"
                                    Header="Address1" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=City}"
                                    Header="City" Width="SizeToHeader" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Country}"
                                    Header="Country" Width="SizeToHeader" />
                <DataGridTemplateColumn Header="Edit">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Edit" Click="EditButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Delete">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Delete" Click="DeleteButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>                    
                </DataGridTemplateColumn>               
            </DataGrid.Columns>
        </DataGrid>
        <Label Content="Printer Configuration" FontSize="16" Foreground="Blue" Height="28" HorizontalAlignment="Left" Margin="8,5,0,0" Name="Title" VerticalAlignment="Top" Width="272" />
        <Button Content="Add Printer" Height="23" HorizontalAlignment="Left" Margin="409,12,0,0" Name="btnAddPrinter" VerticalAlignment="Top" Width="141" Background="Blue" Foreground="White" FontSize="13" Click="btnAddEmploy_Click" />
    </Grid>
Just copy this code and past your wpf xaml file side of the window after that
public void LoadEmploys()
        {
string employconfigFolder="D:\\Employ.xml"
            var doc = new XmlDocument();
            doc.Load(employconfigFolder);

            XmlNodeList employ = doc.GetElementsByTagName("Employ");

            List<EmployAttribute> authors = new List<EmployAttribute>();

            foreach (XmlNode item in employ)
            {
                bool defaultPrinter = false;

                authors.Add(new PrinterAttribute()
                {
                    Name = item.Attributes["Name"].Value,
                    Email = item.Attributes["Email"].Value,
                    DOB = item.Attributes["DOB"].Value,
                    Address1 = item.Attributes["Address1"].Value,
                    City = item.Attributes["City"].Value,
                    Country = item.Attributes["Country"].Value,
                });
            }
            MyDataGrid.ItemsSource = authors;
        }



 public class EmployAttribute
        {
            public string Name { get; set; }
            public string Email { get; set; }
            public string DOB { get; set; }
            public string Address1 { get; set; }
            public bool City { get; set; }
            public bool Country { get; set; }
        }
you can call LoadEmploys() method in your window_Loaded() its working fine.
Read more ...

Related Posts Plugin for WordPress, Blogger...