相关疑难解决方法(0)

按钮样式的内容仅出现在一个按钮实例中

我有一个视图框:

<Viewbox x:Key="SampleViewbox" >
  <Grid>
    <Ellipse Stroke="#e2e2e0" StrokeThickness="6" Fill="#d5273e" Width="128" Height="128"/>
  </Grid>
</Viewbox>
Run Code Online (Sandbox Code Playgroud)

然后我将其包含在如下样式中:

<Style x:Key="SampleStyle" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Background="Transparent" >
                    <ContentPresenter Content="{StaticResource SampleViewbox}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

现在我用SampleStyle创建了许多按钮

<Grid>   
    <StackPanel>
       <Button Style="{StaticResource SampleStyle}" Height="50" Width="50"></Button>
       <Button Style="{StaticResource SampleStyle}" Height="80" Width="80"></Button>
       <Button Style="{StaticResource SampleStyle}" Height="20" Width="20"></Button>  
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

但是,只有一个按钮有椭圆(视图框)

我怎样才能让所有按钮都有/显示椭圆?

.net c# data-binding wpf wpf-controls

1
推荐指数
2
解决办法
1078
查看次数

标签 统计

.net ×1

c# ×1

data-binding ×1

wpf ×1

wpf-controls ×1