WPF问题修改多个按钮模板中的图像样式

WPF问题修改多个按钮模板中的图像样式,wpf,Wpf,我正在尝试为摄像机创建一个控制面板,该面板有上、下、左、右等按钮。每个摄像机功能上、下、左、右由三个图像表示(见下面的代码),分别为左侧、中间和右侧。控制面板是圆形的,所以角图像有点重叠(在没有视觉效果的情况下解释这一点很复杂)。例如,当我单击“向上”时,我必须隐藏最初的三个图像(左侧、中间和右侧),并显示另外三个表示按钮已按下的左、中和右图像。我通过在按钮模板中设置网格来实现这一点。我的问题是,对于控件的角图像,实际上有四个图像表示这一点。例如,对于左上角,四个图像将表示1。顶部未单击。2.点

我正在尝试为摄像机创建一个控制面板,该面板有上、下、左、右等按钮。每个摄像机功能上、下、左、右由三个图像表示(见下面的代码),分别为左侧、中间和右侧。控制面板是圆形的,所以角图像有点重叠(在没有视觉效果的情况下解释这一点很复杂)。例如,当我单击“向上”时,我必须隐藏最初的三个图像(左侧、中间和右侧),并显示另外三个表示按钮已按下的左、中和右图像。我通过在按钮模板中设置网格来实现这一点。我的问题是,对于控件的角图像,实际上有四个图像表示这一点。例如,对于左上角,四个图像将表示1。顶部未单击。2.点击顶部和3。左键未点击,4。左键单击。我的问题是,当单击顶部控件时,是否需要使顶部按钮中包含的图像具有优先级,或者当单击左侧按钮时,是否需要使左侧按钮中的图像具有优先级。因此,我想在单击顶部按钮时修改左按钮的图像可见属性,反之亦然。这真的很难解释,所以如果没有什么意义,我很抱歉,但如果有人对我的困境感兴趣,我可以根据要求发送源代码

<Grid>

    <Canvas>



            <!--<StackPanel>-->
        <Button Name="TopSide" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height="34" Width="102" 
    Canvas.Left="97" Canvas.Top="60" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   >

        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid Width="100">
                    <Canvas>
                        <Image Name="TopRightNormal" Source="Resources/topright_off.jpg" Height="34" Width="34" Canvas.Left="66"></Image>
                        <Image Name="TopRightDown" Source="Resources/topright_down.jpg" Height="34" Width="34" Canvas.Left="66"  Visibility="Hidden" ></Image>

                        <Image Name="TopNormal" Source="Resources/topcenter_off.jpg" Height="34" Width="34" Canvas.Left="34" />
                        <Image Name="TopPressed" Source="Resources/topcenter_down.jpg" Height="34" Width="34" Canvas.Left="34" Visibility="Hidden" />
                        <Image Name="TopDisabled" Source="Resources/topcenter_off.jpg" Height="34" Width="34" Canvas.Left="34" Visibility="Hidden" />

                        <Image Name="TopLeftNormal" Source="Resources/topleft_off.jpg" Height="34" Width="34" Canvas.Left="2" ></Image>
                        <Image Name="TopLeftDown" Opacity="0" Source="Resources/topleft_down.jpg" Height="34" Width="34" Canvas.Left="2" Visibility="Hidden" ></Image>

                    </Canvas>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="TopNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="TopPressed" Property="Visibility" Value="Visible" />

                        <Setter TargetName="TopRightNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="TopRightDown" Property="Visibility" Value="Visible" />

                        <Setter TargetName="TopLeftNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="TopLeftDown" Property="Visibility" Value="Visible"  />
                        <Setter TargetName="TopLeftDown" Property="Opacity"  Value="100"  />

                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="TopNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="TopDisabled" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>

    </Button>

    <!--</StackPanel>-->

    <!--<StackPanel>-->
    <Button Name="LeftSide" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
            Canvas.Left="100" Canvas.Top="60" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MouseDown="Button_MouseDown_1">
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid  Width="34" Height="100">
                    <Canvas>

                        <Image Name="TopLeftNormal" Source="Resources/topleft_off.jpg" Height="34" Width="34" Canvas.Left="0"></Image>
                        <Image  Name="TopLeftDown" Opacity="0" Source="Resources/topleft_leftdown.jpg" Height="34" Width="34" Canvas.Left="0"  Visibility="Hidden" ></Image>


                        <Image Name="Normal" Source="Resources/leftcenter_off.jpg" Height="34" Width="34" Canvas.Top="32" Canvas.Left="0"/>
                        <Image Name="Pressed" Source="Resources/leftcenter_down.jpg" Visibility="Hidden"  Canvas.Top="32"  Height="34" Width="34" />
                        <Image Name="Disabled" Source="Resources/leftcenter_off.jpg" Visibility="Hidden" Height="34" Width="34" Canvas.Top="32"  />
                    </Canvas>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="Normal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="Pressed" Property="Visibility" Value="Visible" />

                        <Setter TargetName="TopLeftNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="TopLeftNormal" Property="Opacity"  Value="0"  />

                        <Setter TargetName="TopLeftDown" Property="Visibility" Value="Visible"  />
                        <Setter TargetName="TopLeftDown" Property="Opacity"  Value="100"  />

                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="Normal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="Disabled" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>
    </Button>
    <!--</StackPanel>-->


    <!--<StackPanel>-->
    <Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height="34" Width="34" 
    Canvas.Left="165" Canvas.Top="92" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MouseDown="Button_MouseDown_2" >
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <Image Name="Normal" Source="Resources/rightcenter_off.jpg" />
                    <Image Name="Pressed" Source="Resources/rightcenter_down.jpg" Visibility="Hidden" />
                    <Image Name="Disabled" Source="Resources/rightcenter_off.jpg" Visibility="Hidden" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="Normal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="Pressed" Property="Visibility" Value="Visible" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="Normal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="Disabled" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>
    </Button>
    <!--</StackPanel>-->

    <!--<StackPanel>-->
    <Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Height="34" Width="34" 
    Canvas.Left="133" Canvas.Top="124" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  >
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <Image Name="BottomNormal" Source="Resources/bottomcenter_off.jpg" />
                    <Image Name="BottomPressed" Source="Resources/bottomcenter_down.jpg" Visibility="Hidden" />
                    <Image Name="BottomDisabled" Source="Resources/bottomcenter_off.jpg" Visibility="Hidden" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="BottomNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="BottomPressed" Property="Visibility" Value="Visible" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="BottomNormal" Property="Visibility" Value="Hidden" />
                        <Setter TargetName="BottomDisabled" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>
    </Button>
    <!--</StackPanel>-->


    <Image Source="Resources/bottomright_off.jpg" Height="34" Width="34" Canvas.Left="165" Canvas.Top="124"></Image>
    <Image Source="Resources/bottomleft_off.jpg" Height="34" Width="34" Canvas.Left="100" Canvas.Top="124"></Image>
    <!--<ToggleButton Style="{StaticResource MyToggleButtonStyle}" Height="34" Width="34"  Margin="150,100"/>-->


    </Canvas>
</Grid>

好的,我找到了一种方法来访问按钮内的图像。我想隐藏其子控件的按钮模板。我曾经

Image imgTopLeftNormal=LeftSide.Template.FindName(“TopLeftNormal”,LeftSide)作为图像

在代码背后