【发布时间】:2014-08-23 07:09:11
【问题描述】:
我有这种风格:
<Style x:Key="RoundCorner" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid" >
<Border x:Name="border" CornerRadius="8">
<Border.Background>
SlateBlue
</Border.Background>
</Border>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" >
<ContentPresenter.Content>
<StackPanel Orientation="Horizontal">
<Image Source="{TemplateBinding Source}"></Image>
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{TemplateBinding Content}"/>
</StackPanel>
</ContentPresenter.Content>
</ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
gjgj
我有三个使用它的按钮:
<Button Style="{StaticResource RoundCorner}" Name="btnOK" Command="NavigationCommands.GoToPage" CommandParameter="ViewModel/OK.xaml" CommandTarget="{Binding ElementName=frmContent}" ></Button>
<Button Style="{StaticResource RoundCorner}" Name="btnHome" Command="NavigationCommands.GoToPage" CommandParameter="ViewModel/Home.xaml" CommandTarget="{Binding ElementName=frmContent}" ></Button>
<Button Style="{StaticResource RoundCorner}" Name="btnHelp" Command="NavigationCommands.GoToPage" CommandParameter="ViewModel/Help.xaml" CommandTarget="{Binding ElementName=frmContent}" ></Button>
我希望这 3 个按钮实现相同的样式,以显示不同的图像和文本。 第一个按钮上应该写有 OK 和“OK”的图像,第二个按钮相同,但用于“Home”等。我该怎么做?
【问题讨论】:
-
我想您可以通过编写具有公共依赖属性的自定义 UserControl 来设置图像和文本值来实现此目的。看看这个类似的问题:stackoverflow.com/questions/1568883/….