Friday, April 11, 2014

Use of Commands, Expander in WPF

This is for xaml file designer :----

Window x:Class="WpfApplication1.Window2"
        Title="Window2" WindowState="Normal" Width="250">
    <Window.CommandBindings>
        <CommandBinding Command="New"  Executed="CommandBinding_Executed_1"  CanExecute="CommandBinding_CanExecute_1">
            
        </CommandBinding>
    </Window.CommandBindings>
    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >
    <Grid Width="200" HorizontalAlignment="Center">

        <WrapPanel ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.PanningRatio="5" ScrollViewer.PanningMode="VerticalOnly" ScrollViewer.IsDeferredScrollingEnabled="True">
            <StackPanel>
            <TextBlock TextWrapping="Wrap">You can use a Popup to provide a link for a specific <Run TextDecorations="Underline" MouseEnter="run_MouseEnter">term</Run> of interest.</TextBlock>

            <Popup Name="popLink" StaysOpen="False" Placement="Mouse" MaxWidth="200" PopupAnimation="Fade"  AllowsTransparency="True">
                <Border BorderBrush="Beige" BorderThickness="2" Background="White">
                    <TextBlock Margin="10" TextWrapping="Wrap">      For more information, see      <Hyperlink NavigateUri="http://en.wikipedia.org/wiki/Term" Click="lnk_Click">Wikipedia</Hyperlink></TextBlock>
                </Border>
            </Popup>
            <Expander Margin="5" Padding="5" Header="Region One">
                <Button Padding="3">Hidden Button One</Button>
            </Expander>
            <Expander Margin="5" Padding="5" Header="Region Two" >
                <TextBlock TextWrapping="Wrap">      Lorem ipsum dolor sit amet, consectetuer adipiscing elit ...</TextBlock>
            </Expander>
            <Expander Margin="5" Padding="5" Header="Region Three">
                <Button Padding="3" Height="30" Width="150" Click="Button_Click_2">Hidden Button Two</Button>
            </Expander>
            <Expander Margin="5" Header="Name" Padding="5" BorderBrush="White" Background="DimGray">
                <StackPanel>
                <TextBlock TextWrapping="Wrap" Padding="5" >Himanshu</TextBlock>
                <Button Command="New" Height="20" Width="150" Click="Button_Click_1" >
                    NEW
                </Button>
                </StackPanel>
            </Expander>
    
        </StackPanel>
        </WrapPanel>

    </Grid>
    </ScrollViewer>
</Window>


This code to write in cs file:---


private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("Use of Commands");
        }
 
        
        private void CommandBinding_CanExecute_1(object sender, CanExecuteRoutedEventArgs e)
        {
            if (isDirty == true)
            {
                e.CanExecute = isDirty;
            }
            
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            isDirty = true;
        }

No comments:

Post a Comment