无法设置 3 个使用相同样式的切换按钮文本内容

Cant set 3 toggle button text content which use same style

我有三个在 wpf 上使用单一样式资源的切换按钮,现在我无法设置它们的内容,内容被声明多次错误,每个切换按钮都有不同的内容。 每个切换按钮也使用图像作为背景。

<UserControl.Resources>
    <Style x:Key="Chromeless" TargetType="ToggleButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">

                    <Border BorderThickness="0" Width="197" Height="60">

                        <ContentPresenter TextElement.FontFamily="{TemplateBinding TextElement.FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0,0,0,0"/>
                    </Border>

                </ControlTemplate>

            </Setter.Value>
        </Setter>

    </Style>
    <Image  x:Key="page1Pressed" Source="/graph_engine;Component/cucaracha/LD3/button_1.png" Height="60" Width="197" />
    <Image  x:Key="page1" Source="/graph_engine;Component/cucaracha/LD3/button_1_pressed.png" Height="60" Width="197" />

    <Image  x:Key="page2Pressed" Source="/graph_engine;Component/cucaracha/LD3/button_2.png" Height="60" Width="197" />
    <Image  x:Key="page2" Source="/graph_engine;Component/cucaracha/LD3/button_2_pressed.png" Height="60" Width="197" />

    <Image  x:Key="page3Pressed" Source="/graph_engine;Component/cucaracha/LD3/button_3.png" Height="60" Width="197" />
    <Image  x:Key="page3" Source="/graph_engine;Component/cucaracha/LD3/button_3_pressed.png" Height="60" Width="197" />

</UserControl.Resources>
<Viewbox Stretch="Fill" StretchDirection="Both">
    <Grid Height="60" Name="grid1" Width="591" Margin="0,0,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="197" />
            <ColumnDefinition Width="197" />
            <ColumnDefinition Width="197" />
        </Grid.ColumnDefinitions>
        <ToggleButton  Style="{StaticResource Chromeless}"  Name="page1" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Foreground="{x:Null}" Checked="page1_Checked" Unchecked="page1_Unchecked">
            <DynamicResource ResourceKey="page1"/>
        </ToggleButton>
        <ToggleButton Grid.Column="1" Style="{StaticResource Chromeless}"  Name="page2" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Foreground="{x:Null}" Unchecked="page2_Unchecked" Checked="page2_Checked">
            <DynamicResource ResourceKey="page2"/>
        </ToggleButton>

        <ToggleButton Grid.Column="2" Style="{StaticResource Chromeless}"  Name="page3" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Foreground="{x:Null}" Checked="page3_Checked" Unchecked="page3_Unchecked">
            <DynamicResource ResourceKey="page3"/>
        </ToggleButton>
    </Grid>
</Viewbox>

你的意思是按下切换按钮后无法更改图像?您只需将图像设置为切换按钮的内容。您可以使用 Visual State Manager 更改背景,例如 this

如果你只是想设置图像而失败了。请检查图片路径。