Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Inside ItemsControl, untoggle previous toggled Button

$
0
0

Right now, I'm using a Listbox, but I don't need to keep track of the selecteditem. Look at the code:

<ListBox ItemsSource="{Binding Polls}" ItemContainerStyle="{StaticResource ListBoxItemPollTemplate}" Style="{DynamicResource LoggableListBox}" HorizontalContentAlignment="Stretch" BorderBrush="#FF2D77FD" Background="{x:Null}"><ListBox.ItemTemplate><DataTemplate><DockPanel><TextBlock HorizontalAlignment="Left" Text="{Binding Name}"/><Button Command="{Binding Path=DataContext.Send, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                    CommandParameter="{Binding}"
                    			    Content="Enviar" HorizontalAlignment="Right" Width="79" Style="{DynamicResource ButtonStyleBlack}" Foreground="{DynamicResource BrushForegroundTextGray}" Cursor="Hand" FontSize="12"/></DockPanel></DataTemplate></ListBox.ItemTemplate></ListBox>

<Style x:Key="LoggableListBox" BasedOn="{StaticResource ListBoxStyleDark}" TargetType="ListBox"><Style.Triggers><DataTrigger Binding="{Binding Items.Count, RelativeSource={x:Static RelativeSource.Self}}" Value="0"><Setter Property="Template"><Setter.Value><ControlTemplate><Border VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="1" BorderBrush="#FF575757" Background="#00000000" Padding="10" Margin="10"><TextBlock FontSize="20" Foreground="{DynamicResource BrushForegroundTextGray}">Nenhum item para mostrar</TextBlock></Border></ControlTemplate></Setter.Value></Setter></DataTrigger><MultiDataTrigger><MultiDataTrigger.Conditions><Condition Binding="{Binding Items.Count, RelativeSource={x:Static RelativeSource.Self}}" Value="0"/><Condition Binding="{Binding DataContext.IsUserLogged, RelativeSource={x:Static RelativeSource.Self}}" Value="False"/></MultiDataTrigger.Conditions><Setter Property="Template"><Setter.Value><ControlTemplate><Border VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="1" BorderBrush="#FF575757" Background="#00000000" Padding="10" Margin="10"><TextBlock FontSize="20" Foreground="{DynamicResource BrushForegroundTextGray}"><Hyperlink Command="{Binding DataContext.ShowLogin, RelativeSource={x:Static RelativeSource.Self}}">Entre</Hyperlink><Run> para acessar essa funcionalidade</Run></TextBlock></Border></ControlTemplate></Setter.Value></Setter></MultiDataTrigger></Style.Triggers></Style>

Several things happening there, but the important thing is that each Item has a Button in it.

1. I will change this to be an ItemsControl, because I don't need to keep track of the selected item.

2. I need to modify the Button in the template to be a ToggleButton. This ToggleButton will tell the user which item is "selected".

3. When the user click in the ToggleButton, the previous toggled button has to "untoggle".

The 1 and 2 requirements I can do well, but how can I accomplish the 3rd requirement?


Take a look at WPF FlashMessage
About.me


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>