Showing posts with label xaml. Show all posts
Showing posts with label xaml. Show all posts

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 ...

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 ...

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...