【问题标题】:windows phone 7 image checkboxwindows phone 7 图像复选框
【发布时间】:2011-07-12 16:49:06
【问题描述】:

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

<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 查找图像并更改其源,但我不知道如何 任何帮助表示赞赏

【问题讨论】:

    标签: c# windows-phone-7 silverlight-3.0


    【解决方案1】:

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

    Here 是一篇非常好的文章,自定义了一个复选框来充当切换按钮。

    WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox

    您可以使用相同的方法来呈现每种视觉状态的图像。

    【讨论】:

    【解决方案2】:

    您应该重新设计(设置自定义样式)复选框以实现所需的输出,而不是这样做。

    在自定义样式中,使用“Checked”VisualState 隐藏和显示相应的图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 1970-01-01
      • 2012-02-29
      相关资源
      最近更新 更多