Button和ListBox代码已经使用了一个静态资源:
<StackPanel Orientation = "Vertical">
<Button x:Name="ololo1" Margin="0,10,0,0" Command="{Binding CommandDump}" Background="Purple" Foreground="White" FontFamily="{StaticResource FontFamily-Sketch}">Text</Button>
...
<ListBox local:ListBoxBehaviors.AutoSizeItemCount="3" ItemsSource="{Binding ItemsCollection}" HorizontalContentAlignment="Center" DisplayMemberPath="Item1" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</StackPanel>
我只需要添加:
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
怎么做?
我试过了:
<ListBox ...>
<ListBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</ListBox.Resources>
<!--...-->
</ListBox>
列表框但仍然不好(
答案 0 :(得分:0)
你需要使用window / userControl.resources(取决于你的使用),下面的例子使用UserControl,将它用于窗口只需将usercontrol更改为window:
<UserControl.Resources>
<Style TargetType="{x:Type Button}" x:Key="BorderStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="3,0,0,0" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
在你的边境:
<Button Style="{StaticResource BorderStyle}"/>
答案 1 :(得分:0)
如果您想将其设置为全局样式,只需将其嵌入Application
类的xaml中,如下所示:
<Application x:Class="YourNamespace"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>