我一直在努力嘗試製作資源字典數週。資源字典是如果我添加一個按鈕或複選框,他們將已被格式化。我有幾個問題,除了按鈕之外什麼都不能用,我在Visual Studio中使用了Silverlight,下面是App.xaml部分的代碼,這部分不應該有任何問題,但我正在在這裏,以防萬一。Silverlight中的資源字典
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources_Theme\Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
以下凡被註釋掉作爲複選框的代碼就是這個問題應該說謊。我得到的錯誤是在解析規則PropertyElement不該出現的屬性:: =。PROPERTYELEMENT內容?ENDTAG ..我不知道如何解決這個問題,我已經嘗試了幾件事。按鈕工作正常,但複選框沒有。複選框和按鈕之間的代碼應該相當類似,所以我不確定代碼在哪裏錯了。如果有人能幫助我,那會很棒。此外,作爲一種次要問題有人能告訴我怎麼去前景色=「白」的FontFamily =「Arial粗體字號=」 16" 上的按鈕工作。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
x:Class="DanaTraining.App">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--Button-->
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle RadiusY="20" RadiusX="20" Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.828"/>
<GradientStop Color="#FF4F1818" Offset="0.491"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--CheckBox-->
<Style TargetType="CheckBox" x:Key="CheckBoxStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid>
<CheckBox>
<CheckBox.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.828"/>
<GradientStop Color="#FF4F1818" Offset="0.491"/>
</LinearGradientBrush>
</CheckBox.Foreground>
</CheckBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
最後,如果有人可以告訴我要爲Silverlight找到一個資源字典模板,這真是太棒了我真的很喜歡
那當我試圖獲得Foreground =「White」FontFamily =「Arial Bold FontSize =」16「以使用按鈕時,它肯定已經結束了。無論哪種方式,這個評論是不回答我問的兩個問題之一。 1)如何解決複選框(按鈕已經工作,我不需要)或2)如何獲得Foreground =「White」FontFamily =「Arial Bold FontSize =」16「與按鈕工作 – netgen
我認爲你的問題在這裏並不是如何獲得Foreground =「White」來處理按鈕,因爲這與已發貨的作品一樣。您正在爲按鈕創建一個新模板,因此您需要處理如何在模板中處理諸如Foreground之類的屬性。模板綁定和模板控件在WPF中有大量的資源在線幫助 – daniellepelley