按下时将按钮更改为绑定颜色
我想在按下时更改按钮颜色:
<DataTemplate>
<!--Click="btn_Click"-->
<ItemsControl DataContext="{Binding}" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Name="btn"
DataContext="{Binding}"
Height="65" Width="79"
Background="Gray"
>
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Ellipse Name="elipse1" Height="65" Width="79" Fill="{Binding Path=ButtonColor}" Visibility="Collapsed"></Ellipse>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="elipse1" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
似乎没有比我使用 all triger <> 更进一步的工作了。未显示灰色按钮是否该模板比绑定更强?这是真的吗?结局如何呢?
i want to change my button color when is pressed :
<DataTemplate>
<!--Click="btn_Click"-->
<ItemsControl DataContext="{Binding}" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Name="btn"
DataContext="{Binding}"
Height="65" Width="79"
Background="Gray"
>
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Ellipse Name="elipse1" Height="65" Width="79" Fill="{Binding Path=ButtonColor}" Visibility="Collapsed"></Ellipse>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="elipse1" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
it doesnt seem to work farther then that wjen i use the all triger <> the gray button is not showen has if this template is stronger then the binding ?is it true ? how to outcome it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,当未按下按钮时 - 它没有视觉影响(Visibility =“Collapsed”) - 按钮内没有元素 - 因此它变得不可见(然后很难按下它:))。
您需要在 ControlTemplate 中添加除椭圆之外的其他内容,以使其显示某些内容而不是椭圆。
The problem is that when the button isn't pressed - it has no visual impact (Visibility="Collapsed") - there are no elements inside the Button - thus it becomes invisible (and then it is hard to Press it :)).
You need to put something besides the Ellipse in the ControlTemplate to have it show something instead of the ellipse.