SIlverlight DataTrigger的问题

E次奥 2015-01-23 10:18:03

在WPF中可以很方便的用DataTrigger改变控件属性等等操作,但是在SIlverlight中就不起作用了;

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:ia="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
xmlns:iv="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
x:Class="SilverlightApplication1.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="VisiblityStyleKey" TargetType="sdk:Label">
<iv:Interaction.Triggers>
<ia:DataTrigger Binding="{Binding ElementName=xianshi,Path=IsChecked}" Value="True">
<ia:ChangePropertyAction PropertyName="Visibility" Value="Visible"/>
</ia:DataTrigger>
<ia:DataTrigger Binding="{Binding ElementName=yincang,Path=IsChecked}" Value="True">
<ia:ChangePropertyAction PropertyName="Visibility" Value="Collapsed"/>
</ia:DataTrigger>
</iv:Interaction.Triggers>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<RadioButton Canvas.Left="630.499" Canvas.Top="511" Content="显示" Height="16" IsChecked="True" x:Name="xianshi" GroupName="Group1" Margin="61,188,233,96"/>
<RadioButton Canvas.Left="752.499" Canvas.Top="511" Content="隐藏" Height="16" x:Name="yincang" GroupName="Group1" Margin="229,188,54,96"/>
<sdk:Label Content="为毛不隐藏" HorizontalAlignment="Left" Height="27" Margin="133,108,0,0" VerticalAlignment="Top" Width="153" Style="{StaticResource VisiblityStyleKey}"/>
</Grid>
</UserControl>


怎么改?
...全文
149 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
E次奥 2015-01-23
  • 打赏
  • 举报
回复
引用 6 楼 duanzi_peng 的回复:
[quote=引用 3 楼 duanzi_peng 的回复:] [quote=引用 2 楼 porenasckx 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
不是啊,下边的RadioButton一个是xianshi,一个是yincang; WPF很简单的东西啊,在SIlverlight中不知道怎么搞;[/quote] 这个我知道呀,但是你的 elementName指定的控件名称 没有在style标签里呀。 [/quote] 你可以 用blend,添加datatrigger,然后把样式 贴到vs里,再修修改。[/quote] 这样不行啊,现在的问题是怎么把Triggers这段代码提取出去
exception92 2015-01-23
  • 打赏
  • 举报
回复
引用 3 楼 duanzi_peng 的回复:
[quote=引用 2 楼 porenasckx 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
不是啊,下边的RadioButton一个是xianshi,一个是yincang; WPF很简单的东西啊,在SIlverlight中不知道怎么搞;[/quote] 这个我知道呀,但是你的 elementName指定的控件名称 没有在style标签里呀。 [/quote] 你可以 用blend,添加datatrigger,然后把样式 贴到vs里,再修修改。
E次奥 2015-01-23
  • 打赏
  • 举报
回复
引用 1 楼 duanzi_peng 的回复:
...
还有就是把Style里边的代码直接放到Lable内部,是有效果的; 我想做的是有多个Lable时总不能每个Lable都写一遍,所以才想提取出来;
E次奥 2015-01-23
  • 打赏
  • 举报
回复
引用 3 楼 duanzi_peng 的回复:
[quote=引用 2 楼 porenasckx 的回复:] [quote=引用 1 楼 duanzi_peng 的回复:] 应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
不是啊,下边的RadioButton一个是xianshi,一个是yincang; WPF很简单的东西啊,在SIlverlight中不知道怎么搞;[/quote] 这个我知道呀,但是你的 elementName指定的控件名称 没有在style标签里呀。 [/quote] 但是WPF可以啊,我这是把WPF的代码改为SIlverlight时发现的问题;WPF完全没问题
exception92 2015-01-23
  • 打赏
  • 举报
回复
引用 2 楼 porenasckx 的回复:
[quote=引用 1 楼 duanzi_peng 的回复:] 应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
不是啊,下边的RadioButton一个是xianshi,一个是yincang; WPF很简单的东西啊,在SIlverlight中不知道怎么搞;[/quote] 这个我知道呀,但是你的 elementName指定的控件名称 没有在style标签里呀。
E次奥 2015-01-23
  • 打赏
  • 举报
回复
引用 1 楼 duanzi_peng 的回复:
应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
不是啊,下边的RadioButton一个是xianshi,一个是yincang; WPF很简单的东西啊,在SIlverlight中不知道怎么搞;
exception92 2015-01-23
  • 打赏
  • 举报
回复
应该是找不到xianshi 吧,wpf写过,silverlight 没有写过。
E次奥 2015-01-23
  • 打赏
  • 举报
回复
有人实现过了么,来个人帮忙啊

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧