另一个WPF图片按钮问题 [英] Yet another WPF image button question

查看:135
本文介绍了另一个WPF图片按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我知道这个主题已经被讨论过了,并且我已经看过许多教程,帖子等,但是似乎没有一个可以满足我的需要,所以就这样-
一个.我有一个WPF应用程序(大量使用图形),其中一个按钮(自定义)需要执行以下操作-
1.用图片1初始化
2.点击-图片2出现
3.再次单击-返回图像1,然后强制

切换按钮似乎无法解决问题.

有什么想法吗?
我不害怕编写代码(建议使用C#)

问候,Anat

Here we go, I know the subject has been chewed on and I''ve seen many tutorials, posts, etc, but none seems to be providing what I need, so here it goes -
a. I have a WPF application (heavy on graphics), where one of the buttons (customized) need to do the following -
1. Initialize with image 1
2. Click on -- Image 2 comes up
3. Another click -- back to image 1 and so force

Toggle button does not seem to do the trick.

Any ideas ?
I''m not afraid from writing code (prefer C#)

Regards, Anat

推荐答案

您正在使用WPF,所以这很容易.
您可以做的是将复选框样式设置为看起来像按钮,然后使用它.

选中此复选框时,显示图像1,而未选中该复选框,则显示图像2.
You are using WPF so this is easy.
What you could do is style a checkbox to look like a button and then use it.

When the checkbox is checked show image 1 and when it is unchecked show image 2.


类似的操作应该起作用(您可能需要对其进行一些调整以适应您的需求):

Something like this should work (you may have to tweak it a little to suite your needs):

<ToggleButton Margin="110,100,247,179">
  <ToggleButton.Style>
      <Style TargetType="{x:Type ToggleButton}">
          <Setter Property="Content">
              <Setter.Value>
                  <Image Source="/WpfApplication1;component/off.png" />
              </Setter.Value>
          </Setter>
          <Style.Triggers>
              <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content">
                      <Setter.Value>
                          <Image Source="/WpfApplication1;component/on.png" />
                      </Setter.Value>
                  </Setter>
              </Trigger>
          </Style.Triggers>
      </Style>
  </ToggleButton.Style>
</ToggleButton>


这篇关于另一个WPF图片按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆