Windows Phone 7 图像复选框 [英] windows phone 7 image checkbox

查看:16
本文介绍了Windows Phone 7 图像复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的复选框,它是一个图像而不是经典的.我设法创建了控件并为其分配了不同的行为,但是在选中/取消选中时我无法使其工作.代码如下:

I'm trying to create a simple checkbox, which is an image instead of the classic one. I managed to create the control and assign it different behaviours, but I can't make it to work when checking/unchecking. Here's the code :

<UserControl.Resources>
        <ControlTemplate x:Key="CheckboxImageTemplate" TargetType="CheckBox">
            <Image Name="imgTreble" MinWidth="100" Source="Images/treble_unchecked.png"/>

        </ControlTemplate>
    </UserControl.Resources>


<StackPanel x:Name="LayoutRoot" Background="{StaticResource PhoneForegroundBrush}">
        <CheckBox Height="72" HorizontalAlignment="Left" x:Name="checkBox1" Background="White" VerticalAlignment="Top" Template="{StaticResource CheckboxImageTemplate}" >
            <Custom:Interaction.Triggers>
                <Custom:EventTrigger EventName="Checked">
                    <ic:ChangePropertyAction PropertyName="Source" TargetName="imgTreble" Value="Images/treble_checked.png"/>
                </Custom:EventTrigger>
                <Custom:EventTrigger EventName="Unchecked">
                    <ic:ChangePropertyAction PropertyName="Source" TargetName="imgTreble" Value="Images/treble_unchecked.png"/>
                </Custom:EventTrigger>
            </Custom:Interaction.Triggers>
        </CheckBox>
    </StackPanel>

我认为问题在于我试图更改其中一个控件(在本例中为复选框)的控件模板项(图像)的属性.TargetName 可能有问题,我应该以不同的方式引用如何告诉 EventTrigger 查找图像并更改其来源,但我不知道如何任何帮助表示赞赏

I think that the problem's that I'm trying to change a property for one of the control's (in this case, the checkbox) controltemplate's items (the image). There's probably a problem with TargetName, and I should be referencing in a different way how to tell the EventTrigger to look for the image and change its source, but I don't know how Any help is appreciated

推荐答案

为此,您需要在复选框的 ControlTemplate 中使用 VisualStates.

For that purpose you need to use VisualStates in your checkbox's ControlTemplate.

这里 是一篇很好的文章,它自定义了一个复选框来充当切换按钮.

Here is a very good article that customizes a checkbox to act as toggle button.

WP7 工作使用 VisualStates:如何从 CheckBox 制作 ToggleSwitch

您可以使用相同的方法为每个视觉状态呈现图像.

You can use the same method to present images for each visual state.

这篇关于Windows Phone 7 图像复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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