2009-07-27 28 views
7

Tôi biết bạn có thể làm điều đó trong CodeBehind với một cái gì đó như thế này ...Có cách nào để bỏ qua lỗi Visual Studio do XAML đưa ra không?

#pragma warning disable 67 
... 
#pragma warning restore 67 

Nhưng có một cách để làm kiểu này mà trong XAML?

Ví dụ, tôi đã điều sau đây trong App.xaml tôi ...

<FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily> 

Và nó giữ ném cho tôi những VS lỗi (mặc dù nó được xây dựng thành công) ...

Lỗi 1 Loại 'FontFamily' không phải là có thể sử dụng làm thành phần đối tượng vì nó không công khai hoặc không xác định một công cụ xây dựng không cần tham số công khai hoặc loại trình chuyển đổi. C: \ Users \ jed.hunsaker \ Documents \ Work \ NextGen \ src \ ESO.App.Reporting \ ESO.App.Reporting.UI.Silverlight \ App.xaml 8 4 ESO.App.Reporting.UI.Silverlight

và ...

Lỗi 2 Các loại 'fontFamily' không hỗ trợ trực tiếp nội dung. C: \ Users \ jed.hunsaker \ Documents \ Work \ NextGen \ src \ ESO.App.Reporting \ ESO.App.Reporting.UI.Silverlight \ App.xaml 8 42 ESO.App.Reporting.UI.Silverlight

Trừ khi các bạn biết cách tốt hơn để lưu trữ một FontFamily trong App.xaml của bạn, tôi là tất cả các tai!

Trả lời

2

Bạn nên sử dụng từ điển tài nguyên. Dưới đây là một ví dụ:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

    <FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily> 
</ResourceDictionary> 

Và bạn nên tham khảo trong bạn App.xaml như vậy (giả sử họ đang ở trong một thư mục Resources):

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       x:Class="SilverlightApplication3.App" 
       > 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Resources/Fonts.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 
Các vấn đề liên quan