1551 Pro WPF 4.5 in C#, 4th Edition

Gratis

0
0
1095
3 months ago
Preview
Full text

®

  Packedwith no-nonsense examples and practical advice, this book will teach you everything you need to know in order to use WPF in a professional setting. The book begins by building a firm foundation of elementary concepts, using your existing C# skills as a frame of reference, before moving on to discuss advanced concepts and demonstrate them in a hands-on way that emphasizes the time and effort savings that can be gained.

Pro WPF 4.5 in C#

  Packedwith no-nonsense examples and practical advice, this book will teach you everything you need to know in order to use WPF in a professional setting. The book begins by building a firm foundation of elementary concepts, using your existing C# skills as a frame of reference, before moving on to discuss advanced concepts and demonstrate them in a hands-on way that emphasizes the time and effort savings that can be gained.

Contents at a Glance

Chapter 9: Commands .......................................................................................................243 Chapter 15: Animation Basics ...........................................................................................391 Chapter 14: Effects and Visuals ........................................................................................369 Chapter 13: Geometries and Drawings .............................................................................347 Chapter 12: Shapes, Brushes, and Transforms ................................................................307 Part III: Drawing and Animation ........................................................................................305 Chapter 11: Styles and Behaviors .....................................................................................283 Chapter 10: Resources ......................................................................................................269  About the Author ..............................................................................................................xxvi  About the Technical Reviewer .........................................................................................xxvii Acknowledgments ..........................................................................................................xxviii  Introduction ......................................................................................................................xxix Part I: Fundamentals .............................................................................................................1 Chapter 7: The Application ................................................................................................195 Chapter 6: Controls ............................................................................................................143 Part II: Deeper Into WPF ....................................................................................................141 Chapter 5: Routed Events ..................................................................................................105 Chapter 4: Dependency Properties .....................................................................................93 Chapter 3: Layout ................................................................................................................53 Chapter 2: XAML ..................................................................................................................21 Chapter 1: Introducing WPF ..................................................................................................3 Chapter 8: Element Binding ..............................................................................................227 n CONTENTS AT A GLANCE Chapter 25: Menus, Toolbars, and Ribbons ......................................................................787 Chapter 32: The Add-in Model ..........................................................................................997 Chapter 31: Multithreading ...............................................................................................983 Chapter 30: Interacting with Windows Forms ..................................................................967 Part VIII: Additional Topics ................................................................................................965 Chapter 29: Printing ..........................................................................................................935 Chapter 28: Documents .....................................................................................................883 Part VII: Documents and Printing ......................................................................................881 Chapter 27: 3-D Drawing ...................................................................................................837 Chapter 26: Sound and Video ............................................................................................813 Chapter 24: Pages and Navigation ....................................................................................741 Chapter 16: Advanced Animation .....................................................................................431 Chapter 23: Windows ........................................................................................................707 Part VI: Windows, Pages, and Rich Controls ....................................................................705 Chapter 22: Lists, Trees, and Grids ...................................................................................665 Chapter 21: Data Views .....................................................................................................647 Chapter 20: Formatting Bound Data .................................................................................601 Chapter 19: Data Binding ..................................................................................................557 Part V: Data ........................................................................................................................555 Chapter 18: Custom Elements ...........................................................................................505 Chapter 17: Control Templates ..........................................................................................465 Part IV: Templates and Custom Elements .........................................................................463 Chapter 33: ClickOnce Deployment ................................................................................1021 Index ................................................................................................................................1041 P A R T I Fundamentals

ChAPTeR 1

Introducing WPF

  WPF is the best toolkit to use if you want to build a rich desktop application that runs on WindowsVista, Windows 7, and Windows 8 in desktop mode (as well as the corresponding versions of WindowsServer). They can provide improvements in efficiency, reduce complexity, and add prebaked features so you don’t have to code them yourself; but they can’t remove the fundamentallimitations of a system component that was designed more than a decade ago.

DirectX: The New Graphics Engine

  Its designmandate was speed, and so Microsoft worked closely with video card vendors to give DirectX the hardware acceleration needed for complex textures, special effects such as partial transparency, and three-dimensional graphics. You alsobenefit from hardware acceleration, which simply means DirectX hands off as much work as possible to the graphics processing unit (GPU), which is the dedicated processor on the video card.

Hardware Acceleration and WPF

  So if you run a WPF application on a computer with a legacy videocard, the interface will still appear the way you designed it. Even more impressively, it gives you the tools to integrate video content into the rest of youruser interface, allowing you to pull off exotic tricks such as placing a video window on a spinning 3-D cube.

Resolution Independence

  Most importantly, you need to realize that WPF bases its scaling on the system DPI setting, not the DPI of your physical display device. Similarly, if you’re using a laptop with a high- resolution display, you probably expect to have slightly smaller windows—it’s the price you pay to fit allyour information onto a smaller screen.

WPF Units

  Using a dash of Pythagoras, you can calculate the pixel density for this monitor, as shown here: = 100 dpi In this case, the pixel density works out to 100 dpi, which is slightly higher than what Windows assumes. WPF uses the following calculation to figure out how it should translate its logical units to physical device pixels: [Physical Unit Size] = [Device-Independent Unit Size] x [System DPI] = 1/96 inch x 120 dpi= 1.25 pixels In other words, when you set the system DPI to 120 dpi, the WPF rendering engine assumes one device-independent unit equals 1.25 pixels.

Windows Vista 1. Right-click your desktop and choose Personalize

  In the list of links on the left, choose Adjust Font Size (DPI). (For example,175% scales the standard 96 dpi to 168 dpi.) In addition, when using a customDPI setting, you have an option named Use Windows XP Style DPI Scaling, which is described in the sidebar “DPI Scaling.” Figure 1-1.

Windows 7 and Windows 8 1. Right-click your desktop and choose Personalize

  In the list of links at the bottom-left of the window, choose Display. You’ll notice that the first two are the same standards found in Windows Vista and Windows XP, while thethird one is larger still.

DPI SCAlIng

  Note milcore.dll is sometimes referred to as the engine for “managed graphics.” Much as the commonnlanguage runtime (CLR) manages the lifetime of a . You simply create the objects with the content you want to show, and milcore.dll paints the appropriate portions of the window as it is dragged around, covered and uncovered,minimized and restored, and so on.

The Class Hierarchy

  But before you begin, it’s helpful to take a first look at the hierarchy of classes that leads to the basic set of WPFcontrols. Figure 1-3 shows a basic overview with some of the key branches of the class hierarchy.

System.Threading.DispatcherObject

  By deriving from DispatcherObject, every element in your user interface can verify whether code is running on the correct thread and access the dispatcher to marshal code to the user interface thread. Early on in the design cycle, the WPF architects decided to create a more powerful property model that baked in features such aschange notification, inherited default values, and more economical property storage.

System.Windows.Controls.Control

  The most impressive part of this model (which is described in more detail in Chapter 6) is the fact that this single piece of content can be anything from an ordinary string to a layout panel with a combination of other shapes and controls. List controls are remarkably flexible—for example, using the features that are built into the ItemsControl class,you can transform the lowly ListBox into a list of radio buttons, a list of check boxes, a tiled display of images, or a combination of completely different elements that you’ve chosen.

The WPF Toolkit

  But the WPF Toolkit isn’t just a place to previewthe future direction of WPF—it’s also a great source of practical components and controls that are made available outside the normal WPF release cycle. Then, pick the Visual C#  Windows group (in the tree on the left), and choose theWPF Application template (in the list on the right).

Multitargeting

  NET Framework You can also change the version you’re targeting at any point afterward by double-clicking the Properties node in the Solution Explorer and changing the selection in the Target Framework list. It also uses this metadata to determine what controls should appearin the Toolbox, what members should appear in the Properties window and Object Browser, and so on, ensuring that the entire IDE is limited to the version you’ve chosen.

The Visual Studio Designer

  After you’ve mastered the syntax of XAML (Chapter 2) and you’ve learned about the family of WPF layout controls (Chapter 3), it’s up to you to choose how you want to create your windows. You can use tools such as data binding and triggers to automate basic user interface behavior (such as text boxes that update themselves when you pagethrough a record source, or labels that glow when you hover overtop with the mouse), all without writing a single line of C#.

ChAPTeR 2

XAML

  Because both tools are equally at home with XAML, you can create a basic user interface with Visual Studio and thenhand it off to a crack design team that can polish it up with custom graphics in Expression Blend. More important, by exploring the tags in a WPF XAML document, you can learn a bit about the object model that underpinsWPF user interfaces and get ready for the deeper exploration to come.

Understanding XAML

  Some of its problems include the following: If you’ve ever been through the process of designing a Windows Forms application with custom graphics in a team setting, you’ve put up with a lot of frustration. After you’ve finished this chapter, you http://windowsclient.net/wpf/white-papers/ may want to read a Microsoft white paper at thenewiteration.aspx that reviews XAML and explores some of the ways developers and designers can collaborate on a WPF application.

XAML Compilation

  When you compile a WPF application in VisualStudio, all your XAML files are converted into BAML, and that BAML is then embedded as a resource into the final DLL or EXE assembly. This might make sensein scenarios that require some of the user interface to be supplied just in time (for example, pulled out of a database as a block of XAML tags).

CReATIng XAMl WITh VISuAl STuDIo

  Here’s how you can attach a name to the Grid: 6 <Grid x:Name="grid1"> 7 </Grid> You can make this change by hand in the XAML document, or you can select the grid in the Visual Studio designer and set the Name property by using the Properties window. (This problem doesn’t affect XAML, because the XAML is parsed and validated at compile time.) Of course, before you can set the properties on a WPF element, you need to know a bit more about the basic WPF properties and data types—a job you’ll tacklein the next few chapters.

Complex Properties

  For example, the Grid has aBackground property that allows you to supply a brush that’s used to paint the area behind the controls. Using the rules of XAML, you can create the LinearGradientBrush object by using an element with the name LinearGradientBrush: <Grid Name="grid1"> <Grid.

Markup Extensions

  In other words, when the XAML parser encounters the previousstatement, it creates an instance of the StaticExtension class (passing in the string “SystemColors.ActiveCaptionBrush” as an argument to the constructor) and then calls ProvideValue() to get the object returned by the SystemColors. Foreground></Button> Depending on the complexity of the markup extension and the number of properties you want to set, this syntax is sometimes simpler.

Attached Properties

  > &lt;Click Me&gt;</Button> When the XAML parser reads this, it correctly understands that you want to add the text <Click Me>, and it passes a string with this content, complete with angle brackets, to the Button. For example, consider this markup: <TextBox Name="txtQuestion" xml:space="preserve" ...> [There is a lot of space inside these quotation marks " ".]</TextBox> In this example, the text in the text box will include the hard return and tab that appear before the actual text.

Using Types from Other Namespaces So far, you’ve seen how to create a basic user interface in XAML by using the classes that are part of WPF

  (Or for an even better list, you can create a data templatethat extracts multiple pieces of information and formats them appropriately. This technique is described in Chapter 20.) To use a class that isn’t defined in one of the WPF namespaces, you need to map the . You’ll also fill in the three italicized bitswith the appropriate information, as explained here: Prefix: This is the XML prefix you want to use to indicate that namespace in your XAML markup.

Code-Only

  When the window is created, the constructor calls an InitializeComponent method that instantiates and configures the button and the form and hooks up the event handler. After you add it to your project, select it in the Solution Explorer, anduse the Properties window to set the Build Action option to None and the Copy to Output Directory option to Copy Always.

ChAPTeR 3

Layout

  IsItemsHost A Boolean value that’s true if the panel is being used to show the items that are associated with an ItemsControl (such as the nodes in a TreeViewor the list entries in a ListBox). (For example, depending on the mode you choose,the InkCanvas supports drawing with the pointer to select onscreen elements. And although it’s a little counterintuitive, you can use the InkCanvas with an ordinary computer and a mouse.) You’ll learn aboutthe InkCanvas in this chapter, and you’ll take a closer look at the VirtualizingStackPanel in Chapter 19.

Simple Layout with the StackPanel

  The StackPanel is one of the simplest layout containers. For example, consider this window, which contains a stack of four buttons: Figure 3-2.

ADDIng A lAyouT ConTAIneR In VISuAl STuDIo

  For instance, in the StackPanel example, it makes sense touse the same margins on the buttons and on the panel itself, as shown here: This way, the total space between two buttons (the sum of the two button margins) is the same as the total space between the button at the edge of the window (the sum of the button margin and theStackPanel margin). (You can find out the size that the button wants by examining the DesiredSize property, which returns theminimum width or the content width, whichever is greater.) The size of the container: If the minimum width is larger than the width of the StackPanel, a portion of the button will be cut off.

AuToMATICAlly SIzeD WInDoWS

  Properties of the Border ClassName Description Background Sets a background that appears behind all the content in the border by using a Brush object. BorderBrush and Sets the color of the border that appears at the edge of the Border object, using aBorderThickness Brush object, and sets the width of the border, respectively.

The WrapPanel

  As this example demonstrates, a WrapPanel inhorizontal mode creates a series of imaginary rows, each of which is given the height of the tallest contained element. In the example on the left in Figure 3-9, all the buttons fit into one tall row and are stretched or aligned to fit.

The DockPanel The DockPanel is a more interesting layout option. It stretches controls against one of its outside edges

  For example, if you dock a button to the top of a DockPanel, it’s stretched across the entire width of the DockPanel but given whatever height it requires (based on the content and theMinHeight property). On the other hand, if you dock a button to the left side of a container, its height is stretched to fit the container, but its width is free to grow as needed.

Nesting Layout Containers

  For example, imagine you want to create a standard dialog box with an OK and Cancel button in the bottom-right corner and a large content region in the rest of the window. For example, if you decide you want the OK andCancel buttons to be centered at the bottom of the window, you simply need to change the alignment of the StackPanel that contains them: <StackPanel DockPanel.

The Grid

  (You can edit the RowDefinitionsand ColumnDefinitions collections by using the Properties window.) After you’ve set up the Grid, you can drag and drop the elements you want into the Grid and configure their margin and alignment settings in theProperties window or by editing the XAML by hand. For example, if you have two proportionately sized rows and you want the first to behalf as high as the second, you could share the remaining space like this: <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="2*"></RowDefinition> This tells the Grid that the height of the second row should be twice the height of the first row.

Layout Rounding

  The column widths are determined by the size of the two buttons at the bottom of the window, which makes it difficult to add new contentinto the existing Grid structure. As this shows, when you choose the layout containers for a window, you aren’t simply interested in getting the correct layout behavior—you also want to build a layout structure that’s easy to maintain andenhance in the future.

Splitting Windows

  If you want to control the maximum and minimum allowed sizes of the columns, you simply make sure the appropriate properties are set in the ColumnDefinitions section, as shown in the previousexample. Resizing a window with two splits Creating this window is fairly straightforward, although it’s a chore to keep track of the three Grid containers that are involved: the overall Grid, the nested Grid on the left, and the nested Grid on the right.

Shared Size Groups

  As the user resizes the column in one Grid, the shared column in the other Grid will follow along, resizing itself at the same time. In the current example, the top and bottom Grid are wrapped in another Grid that accomplishes this purpose, although you could just as easily use a differentcontainer such as a DockPanel or StackPanel.

The UniformGrid

  There is a grid that breaks all the rules you’ve learned about so far: the UniformGrid. The Grid is an all-purpose tool for creating window layouts from the simple to the complex.

Coordinate-Based Layout with the Canvas

  Explicitly positioned buttons in a Canvas If you resize the window, the Canvas stretches to fill the available space, but none of the controls in theCanvas moves or changes size. Tip If you use the Canvas alongside other elements, you may want to consider setting its ClipToBounds to true.nThat way, elements inside the Canvas that stretch beyond its bounds are clipped off at the edge of the Canvas.

Z-Order

  SetZIndex and pass in the element you want to modify and the newZIndex you want to apply. Unfortunately, there is no BringToFront() or SendToBack() method—it’s up to you to keep track of the highest and lowest ZIndex values if you want to implement this behavior.

The InkCanvas

  (You can determine the current mode by using the read-onlyActiveEditingMode property, and you can change the mode used for the back end of the stylus by changing the EditingModeInverted property.) EraseByPoint The InkCanvas erases a portion of a stroke (a point in a stroke) when that portion is clicked. And if you want to add elements between the rows—such as separator lines to divide sections of the window—you can keep the same columns but use the ColumnSpan property to stretch a single elementover a larger area.

Dynamic Content

  (In other words, there’s a blank space where it would have appeared.) This setting is handy if you needto hide and show elements without changing the layout and the relative positioning of the elements in the rest of your window. All you need to do is wrap all the contents of that In this chapter, you took a detailed tour of the WPF layout model and learned how to place elements in stacks, grids, and other arrangements.

ChAPTeR 4

Dependency Properties

  Fortunately, even though the plumbing has changed, you can read and set dependency properties in code in exactly the same way as traditional . If you can’t wait to get started building an application, feel free to skip ahead to the following chapters and then return to this one when you need a deeper understanding of how WPF ticks and you want to builddependency properties of your own.

Understanding Dependency Properties

  That means it’s defined in the FrameworkElement class like this: public class FrameworkElement: UIElement, ...{ public static readonly DependencyProperty MarginProperty;...} By convention, the field that defines a dependency property has the name of the ordinary property, plus the word Property at the end. The field is defined with the readonly keyword, which means it can be set only in the static constructor for the FrameworkElement, which is the task you’ll undertake next.

Registering a Dependency Property

  Properties of the FrameworkPropertyMetadata ClassName Description AffectsArrange, AffectsMeasure, If true, the dependency property may affect how adjacentAffectsParentArrange, and elements (or the parent element) are placed during the measureAffectsParentMeasure pass and the arrange pass of a layout operation. For example, the Margin dependency property sets AffectsMeasure to true, signaling that if the margin of an element changes, the layoutcontainer needs to repeat the measure step to determine the new placement of elements.

How WPF Uses Dependency Properties As you’ll discover throughout this book, dependency properties are required for a range of WPF features

  In other words, if you want to react when a property changes, you have two choices—you can create a binding that uses the property value (Chapter 8), or you can write a trigger that automatically changesanother property or starts an animation (Chapter 11). You can also usean overload of the AddOwner() method that allows you to supply a validation callback and a new FrameworkPropertyMetadata that will apply only to this new use of the dependency property.

Attached Dependency Properties

  Although XAML doesn’t allow it, you can use an overloaded version of the SetValue() method in code to attach a value for any dependencyproperty, even if that property isn’t defined as an attached property. This action won’t change the way the ComboBox works—after all, the code inside the ComboBoxwon’t look for the value of a property that it doesn’t know exists—but you could act upon the PasswordChar value in your own code.

Property Validation

  NewValue);} The end result is that if you set conflicting values, the Minimum takes precedence, the Maximum gets its say next (and may possibly be coerced by the Minimum), and then the Value is applied (and may becoerced by both the Maximum and the Minimum). For example, if you set a Value of 100 when the window loads and set the Maximum property later when the user clicks a button, theValue property is still restored to its rightful value of 100 at that point.

ChAPTeR 5

Routed Events

  Routed events are events with more traveling power—they can tunnel down or bubble up the element tree and be processed by event handlers along the way. As with dependency properties, routed events can be consumed in the traditional way—by connecting an eventhandler with the right signature—but you need to understand how they work to unlock all their features.

Understanding Routed Events

  For example, event routing allows a click that begins in a toolbar button to rise up to the toolbar and then to the containing window before it’s handled by your code. It’s also a necessity for working with the WPF content model, which allows you tobuild simple elements (such as a button) out of dozens of distinct ingredients, each of which has its own independent set of events.

Defining, Registering, and Wrapping a Routed Event

  When registering anevent, you need to specify the name of the event, the type of routine (more on that later), the delegate that defines the syntax of the event handler (in this example, RoutedEventHandler), and the class that owns theevent (in this example, ButtonBase). If the element doesn’t have a defined name (presumably because you don’t need to interact with it in any other place in your code), consider using the name it would have: <Button Click="cmdOK_Click">OK</Button>Tip It may be tempting to attach an event to a high-level method that performs a task, but you’ll have morenflexibility if you keep an extra layer of event-handling code.

Attached Events

  Unfortunately, this apparently obvious code doesn’t work: <StackPanel Click="DoSomething" Margin="5"> <Button Name="cmd1">Command 1</Button><Button Name="cmd2">Command 2</Button> <Button Name="cmd3">Command 3</Button>...</StackPanel> The problem is that the StackPanel doesn’t include a Click event, so this is interpreted by the XAML parser as an error. The best approach is to make sure each button has a Name property set in XAML so that you can access the corresponding objectthrough a field in your window class and compare that reference with the event sender.

Tunneling Events

  For example, ifMouseUp was a tunneled event (which it isn’t), clicking the image in the fancy label example would causeMouseUp to fire first in the window, then in the Grid, then in the StackPanel, and so on, until it reaches the actual source, which is the image in the label. Figure 5-4 shows an example that tests tunneling with the PreviewKeyDown event When you press a key in the text box, the event is fired first in the window and then down through the hierarchy.

IDenTIFyIng The RouTIng STRATegy oF An eVenT

  (The actual time that thisrepresents isn’t terribly important, but you can compare different timestamp values to determine what event took place first. Larger timestamps signify more-recent events.) The Device returns an object thatprovides more information about the device that triggered the event, which could be the mouse, the keyboard, or the stylus. In a real-world test in which you press Shift+S, your text box will actually fire a series ofKeyDown events for the Shift key, followed by a KeyDown event for the S key, a TextInput event (orTextChanged event in the case of a text box), and then a KeyUp event for the Shift and S keys.

Focus

  Essentially, when you press the Tab key, you’ll move to the first child in the current element or, if the current element has no children, to the next child at the same level. That means you can designate anspecific control as the starting point for a window by setting its TabIndex to 0 but rely on automatic navigation to guide the user through the rest of the window from that starting point, according to the order that your elements aredefined.

Getting Key State

  For example, if you have a StackPanel that contains a button and you move the mouse pointer over the button, the MouseEnter event will fire first for the StackPanel (as you enter its borders) and then for thebutton (as you move directly over it). The MouseEventArgs object includes properties that tell you the state that the mouse buttons were in when the event fired, and it includes a GetPosition() method that tellsyou the coordinates of the mouse in relation to an element of your choosing.

Capturing the Mouse

  For example, if you click anelement, hold down the mouse, and then move the mouse pointer off the element, the element won’t receive the mouse up event. You’ll also lose the mouse capture if you don’tfree the mouse after a mouse up event occurs and the user carries on to click a window in another application.

Drag-and-Drop

  First, the GetTouchPoint() method gives you the screen coordinates where the touch event occurred (along withless commonly used data, such as the size of the contact point). It places the ellipse at the appropriate coordinates by using the touch point, addsit to the collection (indexed by the touch device ID), and then shows it in the Canvas: private void canvas_TouchDown(object sender, TouchEventArgs e) {// Create an ellipse to draw at the new contact point.

Manipulation

  For example, to support a rotation, you’d need to detect two contact points on the same element, keep track of how they move, and use some sort of calculation to determine that one isrotating around the other. For example, if the user begins to rotate an image, the ManipulationDelta event will fire continuously, until the user rotation is finished and the user raises up the touched-down fingers.

Inertia

  Right now, if a user drags one of the images in Figure 5-10 by using a panning gesture, the image stops moving the moment the fingers are raised from the touch screen. But before you branch out to this topic, the nextchapter takes a short detour to show you how many of the most fundamental controls (things such as buttons, labels, and text boxes) work in the WPF world.

ChAPTeR 6

Controls

  There are several types of controls that you won’t see in this chapter, including those that create menus, toolbars, and ribbons; those that show grids and trees of bound data; and those that allow richdocument viewing and editing. In the world of WPF, a control is generally described as a user-interactive element—that is, an element that can receive focus andaccept input from the keyboard or mouse.

Background and Foreground Brushes

  Usually, the background is the surface of the control (think of the white or gray area inside the borders of a button), and the foreground is the text. (The names are based on the color names supported by most web browsers.) It thensets the brush as the background brush for the button, which causes its background to be painted a light shade of blue.

RgB AnD SCRgB

  Here’s an example that uses the #aarrggbbnotation to create the same color as in the previous code snippets: <Button Background="#FFFF0000">A Button</Button> Here, the alpha value is FF (255), the red value is FF (255), and the green and blue values are 0. Optionally, you can use the full name of a typeface to get italic or bold, as shown here: <Button FontFamily="Times New Roman Bold">A Button</Button> However, it’s clearer and more flexible to use just the family name and set other properties (such asFontStyle and FontWeight) to get the variant you want.

Text Decorations and Typography

  For the most part, the TextDecorations and Typography features are found only in flow document content—which you use to create rich, readable documents. Additionally, they’re supported by the TextBlock, which is a lighter-weight version of the Label that’s perfect for showing small amounts of wrappable textcontent.

Font Inheritance

  (You can do this in Visual Studio by selectingthe font file in the Solution Explorer and changing its Build Action in the Properties window.) Next, when you use the font, you need to add the character sequence ./# before the font family name, as shown here: <Label FontFamily="./#Bayern" FontSize="20">This is an embedded font</Label> The ./ characters are interpreted by WPF to mean the current folder. Inthis scenario, the current folder is exactly that, and WPF looks at the font files that are in the same directory as the XAML file and makes them available to your application.

Text Formatting Mode

  A large part of the difference is due to WPF’s device-independent display system, but there are alsosignificant enhancements that allow text to appear clearer and crisper, particularly on LCD monitors. The best solution is to scale up your text (on a 96 dpi monitor, the effect should disappear at a text size of about 15 device-independent units) or use a high-dpi monitor that has enough resolution to show sharp text at any size.

Dokumen baru

Aktifitas terkini

Download (1095 Halaman)
Gratis

Tags

1551 Pro Wpf 4 5 In C 4Th Edition Bioethics 4Th Edition Encyclopedia 1642 Javascript For Dummies 4Th Edition Thomson Martinent A Practical English Grammar 4Th Edition Schaum S Outlines Probability And Statistics 4Th Edition C Primer 3Rd Edition Cn Ppt Kk C Pro Sd Tinggi Wiley Publishing C For Dummies 2Nd Edition 4Th Meeting Thermodynamic
Show more