代码之家  ›  专栏  ›  技术社区  ›  yoav.str

按下按钮时,将按钮更改为绑定颜色

  •  0
  • yoav.str  · 技术社区  · 15 年前

                <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>
    

    wjen i使用all triger<>灰色按钮不显示,这似乎不起作用,如果此模板比绑定更强大?是真的吗?结果如何?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Goblin    15 年前

    问题是,当按钮未按下时-它没有视觉影响(Visibility=“Collapsed”)-按钮内没有元素-因此它变为不可见(然后很难按下它:))。

    您需要在ControlTemplate中除椭圆外放置一些内容,使其显示某些内容而不是椭圆。

    推荐文章