PrintTaskOptionChangedEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當列印工作選項變更時呼叫。
public ref class PrintTaskOptionChangedEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class PrintTaskOptionChangedEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class PrintTaskOptionChangedEventArgs
Public NotInheritable Class PrintTaskOptionChangedEventArgs
- 繼承
- 屬性
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
備註
以下是顯示如何在列印工作選項變更時擷取物件的程式碼片段。 首先,應用程式必須註冊以接聽選項變更。 一旦選項變更,就會對事件接聽程式進行回呼。
// Retrieve the advanced Print Task Options.
PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);
// Create a new list option.
PrintCustomItemListOptionDetails margins = printDetailedOptions.CreateItemListOption("Margins", "Margins");
margins.AddItem("WideMargins", "Wide", "Each margin is 20% of the paper size", await wideMarginsIconTask);
margins.AddItem("ModerateMargins", "Moderate", "Each margin is 10% of the paper size", await moderateMarginsIconTask);
margins.AddItem("NarrowMargins", "Narrow", "Each margin is 5% of the paper size", await narrowMarginsIconTask);
// Add the custom option to the option list
printDetailedOptions.DisplayedOptions.Add("Margins");
printDetailedOptions.OptionChanged += printDetailedOptions_OptionChanged;
async void printDetailedOptions_OptionChanged(PrintTaskOptionDetails sender, PrintTaskOptionChangedEventArgs args)
{
string optionId = args.OptionId as string;
if (string.IsNullOrEmpty(optionId))
{
return;
}
if (optionId == "Margins")
{
PrintCustomItemListOptionDetails marginsOption = (PrintCustomItemListOptionDetails)sender.Options["Margins"];
string marginsValue = marginsOption.Value.ToString();
switch (marginsValue)
{
case "WideMargins":
ApplicationContentMarginTop = 0.2;
ApplicationContentMarginLeft = 0.2;
break;
case "ModerateMargins":
ApplicationContentMarginTop = 0.1;
ApplicationContentMarginLeft = 0.1;
break;
case "NarrowMargins":
ApplicationContentMarginTop = 0.05;
ApplicationContentMarginLeft = 0.05;
break;
}
}
}
若要查看此專案的完整清單,以及使用 PrintTask的其他列印案例,請參閱 列印 和 UWP 列印範例。
屬性
OptionId |
取得已變更之列印工作選項的識別碼。 |