Search This Blog

Showing posts with label ContentControl. Show all posts
Showing posts with label ContentControl. Show all posts

Tuesday, June 3, 2014

ComboBoxItem WPF Example

WPF > Controls  > ContentControl > ComboBoxItem 

ComboBoxItem represent an item in a ComboBox.


Example:

XAML


<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ComboBox x:Name="cbo" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" SelectionChanged="ComboBox_SelectionChanged">
            <ComboBoxItem>Option1</ComboBoxItem>
            <ComboBoxItem>Option2</ComboBoxItem>
        </ComboBox>

    </Grid>
</Window>

C#
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  string value = ((ComboBoxItem)cbo.SelectedItem).Content.ToString();
}


Tuesday, November 19, 2013

WPF Frame Control

WPF > Controls  > ContentControl > Frame

WPF frame control is capable of displaying both WPF and HTML content. Also it allows  navigation between different contents.

Example:

 
 
XAML:
 

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
       xmlns:src="clr-namespace:WpfApplication2" Width="362.5"
        >
    <StackPanel>
        <Frame Source="Page1.xaml">
        </Frame>
        <Frame Source="Page1.xaml">
            <Frame.LayoutTransform>
                <RotateTransform Angle="90" />
            </Frame.LayoutTransform>
        </Frame>
    </StackPanel>
</Window>

 

Thursday, October 31, 2013

WPF RepeatButton

WPF > Controls  > ContentControl > RepeatButton

WPF RepeatButton raises its Click event repeatedly from the time it is pressed until it is released.

Properties
  • Interval: gets or sets the amount of time, in milliseconds, between repeats once repeating starts
  • Delay: gets or sets the amount of time, in milliseconds, the RepeatButton waits while it is pressed before it starts repeating
WPF RepeatButton Example:

XAML:

<Grid>
        <RepeatButton Margin="10,10,0,0" VerticalAlignment="Top"
              Delay="500" Interval="500"
              HorizontalAlignment="Left"                      
              x:Name="btnIncrease"  Width="352" Height="30" Click="GrowButton_Click">
            RepeatButton: Click on this button and keep mouse pressed
        </RepeatButton>
        <TextBlock x:Name="txt" HorizontalAlignment="Left" Margin="10,55,0,0" TextWrapping="Wrap" Text="TextBlock"
                   VerticalAlignment="Top" Height="18" Width="352" RenderTransformOrigin="0.5,0.5">
        </TextBlock>
</Grid>

C# Code:

public partial class MainWindow : Window
    {
        int k = 0;
        public MainWindow()
        {
            InitializeComponent();
        }
        private void GrowButton_Click(object sender, RoutedEventArgs e)
        {
            k += 1;
            txt.Text = k.ToString() ;
        }
    }

Wednesday, October 30, 2013

WPF ScrollViewer

WPF > Controls  > ContentControl > ScrollViewer

WPF ScrollViewer control enables scrolling of content.
Sometimes the content is larger than a computer screen display area. This control encapsulates ScrollBar elements and a content container.

WPF ScrollViewer Example:

XAML:

<Window x:Class="ScrollViewer.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="406" Width="411">
    <ScrollViewer HorizontalScrollBarVisibility="Auto"   VerticalScrollBarVisibility="Auto">
       <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
           <TextBlock TextWrapping="Wrap">ScrollViewer Example. Resize the window to see functionality</TextBlock>
           <Rectangle Fill="Blue" Width="400" Height="400"></Rectangle>
       </StackPanel>
   </ScrollViewer>
</Window>


WPF Checkbox

WPF > Controls  > ContentControl > CheckBox

WPF Checkbox  is a control that a user can check/uncheck and clear


WPF Checkbox Example:

XAML:

<Grid>
   <TextBox x:Name="txt1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox"     Width="215" Margin="0,27,0,220"/>
<CheckBox x:Name="chkBox" Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" Checked="chkBox_Checked" Unchecked="chkBox_Unchecked" Indeterminate="chkBox_Indeterminate" IsThreeState="True"/>
</Grid>

C# Code:

private void chkBox_Checked(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox checked";
}
private void chkBox_Unchecked(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox unchecked";
}
private void chkBox_Indeterminate(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox indeterminate";
}



WPF Button

WPF > Controls  > ContentControl > Button

WPF Button represents a Windows button control.
The main event is Click event.

WPF Button Example:

XAML:

<Window x:Class="ButtonExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox x:Name="txt1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" Width="215" Margin="0,27,0,220"/>
        <Button x:Name="btn1" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="btn1_Click"/>
    </Grid>
</Window>

C# Code:

private void btn1_Click(object sender, RoutedEventArgs e)
{
   txt1.Text = "Button was clicked";
}  



Other examples:


ContentControl WPF

WPF > Controls  > ContentControl

ContentControl is a control with a single piece of content of any type and supports only one child.

List of ContentControl: