summaryrefslogtreecommitdiff
path: root/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/PrintPreferenceWindow.xaml
blob: 924efc21a12744bf9d80e29d32986d9cc53e055e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<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>