所以我有一个风格直接放到App.xaml文件为这样的应用:便携式XAML样式
<Application x:Class="Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="OnStartup">
<Application.Resources>
<Style x:Key="SpecialButtonStyle" TargetType="Button">
<Setter Property="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" />
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Block.Foreground" Value="White" />
<Setter Property="TextBlock.Foreground" Value="White" />
<Setter Property="TextElement.Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" Padding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}">
<Border Background="{TemplateBinding BorderBrush}">
<ContentControl Foreground="White">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ContentControl>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
</Application>
我想包括这是在我的班级图书馆风格,因此任何引用该库的xaml项目都可以在设计器中看到“SpecialButtonStyle”作为可选的“样式”。 我读过几篇关于ResourceDictionaries和创建可移植的XAML控件的文章,但我仍然感到困惑。我基本上想要包含作为类库一部分的样式集合。
(我只能发布2个链接,直到我获得了较高的声誉的StackOverflow) http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx
http://visualstudiomagazine.com/articles/2015/03/01/everyone-gets-xaml-with-xamarinforms.aspx
任何帮助将不胜感激。谢谢!
谢谢!一旦我有机会实施这一点,我会尽快回复。 PS。我不能upVote,直到我有15名声望。 – TaterJuice
太棒了。得到它的工作,这是答案! – TaterJuice
很高兴帮助:-) –