【发布时间】: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