programming windows phone 7 phần 7

May mắn thay, có một lớp học trong Silverlight tồn tại đặc biệt để hiển thị nội dung trong một dẫn xuất ContentControl. Lớp đó được gọi là ContentPresenter. Nó có một tài sản có tên là nội dung của loại đối tượng, và hiển thị ContentPresenter đối tượng bất kể cho dù đó là một chuỗi văn bản hoặc bất kỳ yếu tố khác: | Button Here s what we re up to so far The button still displays the text temporary and it should really be displaying the text Click me You might be tempted to put a TextBlock in there and set its Text property to a TemplateBinding of the Content property of the Button TextBlock Text TemplateBinding Content This actually works in this example but it s very very wrong. The problem is that the Content property of the Button is of type object. We can set it to anything an Image a Panel a Shape a RadialGradientBrush and then the TextBlock would have a little problem. Fortunately there is a class in Silverlight that exists specifically to display content in a ContentControl derivative. That class is called ContentPresenter. It has a property named Content of type object and ContentPresenter displays that object regardless whether it s a text string or any other element Button Content Click me HorizontalAlignment Center VerticalAlignment Center Style TargetType Button Setter Property BorderBrush Value StaticResource PhoneAccentBrush Setter Property BorderThickness Value 6 Setter Property Background Value StaticResource PhoneChromeBrush 597 Setter Property Template ControlTemplate TargetType Button Border BorderBrush TemplateBinding BorderBrush BorderThickness TemplateBinding BorderThi ckness Background TemplateBinding Background CornerRadi us 12 ContentPresenter Content TemplateBinding Content Border ControlTemplate Setter Style Button Notice how the Content property of the Contentpresenter is bound to the Content property of the Button. The Contentpresenter has the distinct advantage of working for any kind of object. The Contentpresenter might create its own visual tree for example if the Content is of type string then the Contentpresenter creates a TextBlock to display that string. The Contentpresenter is also entrusted with the job of building a visual tree to display content based on a DataTemplate .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
31    99    2    26-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.