Sample Code

Windows Driver Samples/ Printer Extension Sample/ C#/ ExtensionSample/ PrintPreferenceWindow.xaml/

<Window x:Class="Microsoft.Samples.Printing.PrinterExtension.PrintPreferenceWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:Microsoft.Samples.Printing.PrinterExtension"
        xmlns:sys="clr-namespace:System;assembly=mscorlib" 
        Title="{Binding Path=PrinterQueue.Name}" Height="405" Width="565"
        ResizeMode="NoResize"
        Icon="Fabrikam_Logo.png"
        Closing="PrintPreferenceWindow_Closing"
        >

    <Window.Resources>
        <!-- Resources required to create the basic window  -->
        <Style x:Key="GraySingleBorder" TargetType="Border">
            <Setter Property="BorderBrush" Value="Gray" />
        </Style>

        <SolidColorBrush x:Key="InkStatusBorderBrush" Color="Black"/>

        <BitmapImage x:Key="FabrikamLogo" UriSource="Fabrikam_Logo.png" />

        <Style x:Key="SimpleGroupBox" TargetType="GroupBox">
            <Setter Property="Margin" Value="5,5,5,5" />
            <Setter Property="Padding" Value="0,5,0,0" />
        </Style>
 
        <!-- 
            Each brush below is bound to BidiHelperSource, which provides a data-biding friendly way to
            access ink levels.
        -->
        <LinearGradientBrush x:Key="InkBrushC" StartPoint="0, 1" EndPoint="0, 0">
            <GradientStop Color="Cyan" Offset="{Binding Path=BidiHelperSource.InkLevelC}" />
            <GradientStop Color="White" Offset="{Binding Path=BidiHelperSource.InkLevelC}" />
        </LinearGradientBrush>
        <LinearGradientBrush x:Key="InkBrushM" StartPoint="0, 1" EndPoint="0, 0">
            <GradientStop Color="Magenta" Offset="{Binding Path=BidiHelperSource.InkLevelM}" />
            <GradientStop Color="White" Offset="{Binding Path=BidiHelperSource.InkLevelM}" />
        </LinearGradientBrush>
        <LinearGradientBrush x:Key="InkBrushY" StartPoint="0, 1" EndPoint="0, 0">
            <GradientStop Color="Yellow" Offset="{Binding Path=BidiHelperSource.InkLevelY}" />
            <GradientStop Color="White" Offset="{Binding Path=BidiHelperSource.InkLevelY}" />
        </LinearGradientBrush>
        <LinearGradientBrush x:Key="InkBrushK" StartPoint="0, 1" EndPoint="0, 0">
            <GradientStop Color="Black" Offset="{Binding Path=BidiHelperSource.InkLevelK}" />
            <GradientStop Color="White" Offset="{Binding Path=BidiHelperSource.InkLevelK}" />
        </LinearGradientBrush>
        
        <c:OptionConstrainedToDisplayColorConverter x:Key="OptionConstrainedToColor" />
    </Window.Resources>

    <Grid x:Name="MainGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition x:Name="LeftHalf" Width="3*"/>
            <ColumnDefinition x:Name="RightHalf" Width="5*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="BrandingRow" Height="1*"/>
            <RowDefinition x:Name="ContentRow" Height="2*"/>
            <RowDefinition x:Name="StatusRow" />
        </Grid.RowDefinitions>

        <Border Style="{DynamicResource GraySingleBorder}" Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="0,0,0,1"/>
        <Border Style="{DynamicResource GraySingleBorder}" Grid.Row="1" Grid.Column="0" BorderThickness="0,0,0,1" />
        <Border Style="{DynamicResource GraySingleBorder}" Grid.Row="1" Grid.Column="1" BorderThickness="1,0,0,1" />
        <Border Style="{DynamicResource GraySingleBorder}" Grid.Row="2" Grid.Column="0" BorderThickness="0,0,0,0" />
        <Border Style="{DynamicResource GraySingleBorder}" Grid.Row="2" Grid.Column="1" BorderThickness="1,0,0,0" />

        <Image Source="{StaticResource FabrikamLogo}" Grid.Row="0" Grid.Column="0" Stretch="None"/>

        <!--
            Display the name of the current print queue.
        -->
        <TextBlock FontFamily="Verdana" Grid.Row="0" Grid.Column="1" TextAlignment="Left"
                   VerticalAlignment="Center" FontSize="16" Foreground="DarkOrchid" Text="{Binding Path=PrinterQueue.Name}" />

        <!--
            Lay out multiple GroupBoxes, with one ComboBox inside each. The number of GroupBoxes is determined by the number of features returned by
            binding property: PrintSchemaHelperSource.Features.
            
            Each GroupBox Header displays the print schema feature's display name, bound to PrintSchemaFeatureHelper.DisplayName.
            Each ComboBox's ItemSource property is bound to the list of valid options for that feature i.e. bound to PrintSchemaFeatureHelper.Options.
                Additionally, the ComboBox is bound two-way to to PrintSchemaFeatureHelper.SelectedOption. Therefore, in addition to displaying the option
                selected in the current print ticket, when the selected option is changed via UI selection, 
                a 'set' property is invoked on PrintSchemaFeatureHelper.SelectedOption.

            Each item in the ComboBox has the following structure:
                It's displays the option name via a TextBlock, bound to the IPrintSchemaOption.DisplayName.
                It's 'ForeGround' font color changes based on the IPrintSchemaOption.Constrained property.

            *Note*: Since this is an expensive operation to perfom, the data is retrieved asynchronously (IsAsync=true, below).
        -->
        <StackPanel Grid.Row="1" Grid.Column="1">
            <ItemsControl ItemsSource="{Binding Path=PrintSchemaHelperSource.Features, IsAsync=True}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <GroupBox Style="{DynamicResource SimpleGroupBox}" Header="{Binding Path=DisplayName}">
                            <ComboBox ItemsSource="{Binding Path=Options}" SelectedItem="{Binding Path=SelectedOption}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" >
                                            <TextBlock Text="{Binding Path=DisplayName}" Foreground="{Binding Converter={StaticResource OptionConstrainedToColor}, Path=Constrained}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ComboBox>
                        </GroupBox>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </StackPanel>

        <!--
            This modal dialog prevents the user from making changes to print preferences
            when print ticket validation is in progress. This dialog is hidden when validation is not in progress.
        -->
        <c:ValidationModalDialog x:Name="ValidationModalDialog" Grid.Row="1" Grid.Column="1" Visibility="Hidden"/>

        <!--
            This GroupBox displays ink status. There are 4 rectangles that display ink status. The brush that paints color/level is bound to code.
        -->
        <GroupBox Header="{Binding Path=InkStatusTitle}" Grid.Column="0" Grid.Row="2" Margin="5,0,5,5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="24*"/>
                    <RowDefinition Height="43*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Rectangle Grid.Column="0" Fill="{DynamicResource InkBrushC}" Margin="2,0,2,0" Name="InkIndicatorC" Stroke="{DynamicResource InkStatusBorderBrush}" Grid.RowSpan="2"/>
                <Rectangle Grid.Column="1" Fill="{DynamicResource InkBrushM}" Margin="2,0,2,0" Name="InkIndicatorM" Stroke="{DynamicResource InkStatusBorderBrush}" Grid.RowSpan="2"/>
                <Rectangle Grid.Column="2" Fill="{DynamicResource InkBrushY}" Margin="2,0,2,0" Name="InkIndicatorY" Stroke="{DynamicResource InkStatusBorderBrush}" Grid.RowSpan="2"/>
                <Rectangle Grid.Column="3" Fill="{DynamicResource InkBrushK}" Margin="0,0,2,0" Name="InkIndicatorK" Stroke="{DynamicResource InkStatusBorderBrush}" HorizontalAlignment="Right" Width="43" Grid.RowSpan="2"/>
            </Grid>
        </GroupBox>

        <UniformGrid Grid.Row="2" Grid.Column="2" Rows="1" Columns="3" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,10,10">
            <Button Content="_Ok" Name="OkButton" Margin="0,0,5,0" Click="Button_Click" />
            <Button Content="_Cancel" Name="CancelButton" Margin="5,0,5,0" Padding="10,0,10,0" Click="Button_Click" />
            <Button Content="_Verify settings" Name="VerifyButton" Margin="5,0,0,0" Click="Button_Click" />
        </UniformGrid>
    </Grid>
</Window>

Our Services

  • What our customers say about us?

© 2011-2024 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS