开发者

change button to his binding color when pressed

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜