Problem with statemanager in SL4 - silverlight-4.0

I have a togglebotton
<ToggleButton Padding="1">
<TextBlock>
<Underline>Week</Underline>
</TextBlock>
</ToggleButton>
and what I need to change is set underline to false, when togglebutton is unchecked, and set it to true, when control is ckecked.
and now I have only
<ToggleButton Padding="1">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="IsChecked">
<Storyboard Duration="0:0:0">
and I can't figure out what next .
I'm not stick with conception with textblock. Text in the ToggleButton should be underline and that's all.

In order to use VisualStateManager you would have to redefine the template of the ToggleButton - take a look at the MSDN ToggleButton Syles. Instead of that you can use Blend's triggers. First add to your project System.Windows.Interactivity.dll and Microsoft.Expression.Interactions.dll provided by Expression Blend SDK and then use the following code:
<ToggleButton x:Name="toggleButton" Padding="1">
<TextBlock x:Name="textBlock">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsChecked, ElementName=toggleButton}" Value="True">
<ei:ChangePropertyAction PropertyName="TextDecorations">
<ei:ChangePropertyAction.Value>
<TextDecorationCollection>Underline</TextDecorationCollection>
</ei:ChangePropertyAction.Value>
</ei:ChangePropertyAction>
</ei:DataTrigger>
<ei:DataTrigger Binding="{Binding IsChecked, ElementName=toggleButton}" Value="False">
<ei:ChangePropertyAction PropertyName="TextDecorations"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
Week
</TextBlock>
</ToggleButton>
The ei: and i: are the following:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

Related

UWP-CPP/Winrt Set Corner radius of the ListViewItem when hovered/selected

I am planning to show a list of objects using ListView. According to the design the rectangle around the ListViewItem should be rounded at the corners. Have tried multiple ways to achieve the same but couldn't find a solution.
<ListView
x:Name="ObjectList"
ItemsSource="{x:Bind ObjectViewModel.Objects}"
SelectionChanged="ListViewButtonClick"
MaxWidth ="{StaticResource ColumnMaximumWidth}"
VerticalAlignment = "Center"
HorizontalContentAlignment = "Stretch"
ScrollViewer.HorizontalScrollBarVisibility ="Disabled"
SelectionMode ="Single" />
<ListView.Resources>
<SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="Green" />
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="Green" />
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Margin" Value="0,0,0,30" />
</Style>
</ListView.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:ObjectModel">
<Border
BorderBrush="Red"
BorderThickness="3"
CornerRadius="5">
<Grid MinHeight="66" CornerRadius="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<FontIcon
FontSize="17"
Glyph=""
Style="{StaticResource FontIconStyle1}" />
<TextBlock
Grid.Column="1"
Style="{StaticResource AddBluetoothLabelTextStyle}"
Text="{x:Bind ObjectName, Mode=OneWay}" />
</Grid>
</Border>
</ItemsControl.ItemTemplate>
</ListView>
As shown in the picture the corners of the selected/hovered items is not rounded. Can you please help how this can be achieved. TIA
You need to change the VisualState to set CornerRadius of ListViewItem in style of ListViewItem.
Please check the following steps:
Open generic.xaml file, find a Style whose TargetType is ListViewItem and Key is ListViewItemRevealStyle. Copy the style into your Page.Resources.
Delete the x:Key property of the style so that the style could be used in all ListViewItem in the current Page.
Find a VisualState whose name is Selected, add the following code:
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Target="Root.CornerRadius" Value="10" />
</VisualState.Setters>
</VisualState>
Find VisualStates whose names are PointerOver, PointerOverSelected, PointerOverPressed, PointerOverPressed, add the following code seperately:
<Setter Target="Root.CornerRadius" Value="10" /> <!--Add this code-->
Delete the ListView.ItemContainerStyle statement, which conflicts with the ListViewItem’s style.
Note, it is better if you could follow the above steps first to set corner radius in the style of ListViewItem then add other style or settings later, which could ensure settings in the style of ListViewItem work.

CollectionView GridItemsLayout Change BackgroundColor of nested Item (Button)

I have a problem concerning a CollectionView with a GridItemsLayout. In my application, I have a StackLayout with a horizontal CollectionView(GridItemsLayout), which contains a Button bound to a certain category.
Whenever a button is clicked/tapped, it filters the ListView (of type Surgery) below based on the category. All of that is working fine, however, I would like to highlight the Category/Button by changing it BackgroundColor to see which category is currently used for filtering.
<CollectionView HeightRequest="70"
x:Name="categoryCollection"
ItemsSource="{Binding Categories}"
Margin="20,0,20,0"
SelectionMode="Single">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal" Span="1" HorizontalItemSpacing="5"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="0,5,0,5">
<Button x:Name="categoryButton" Text="{Binding Name}"
Command="{Binding Path=BindingContext.FilterCommand, Source={x:Reference Name=SurgeryListView}}"
CommandParameter="{Binding .}"
CornerRadius="15"
FontFamily="OpenSans" Margin="0,5,10,5"
Opacity="0.6" FontSize="16" TextTransform="None">
</Button>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<ListView x:Name="listView"
ItemsSource="{Binding Surgeries}"
RefreshCommand="{Binding LoadSurgeriesCommand}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True"
RowHeight="70"
BackgroundColor="{StaticResource darkThemeBackground}"
ItemTemplate="{StaticResource surgeryDataTemplateSelector}">
<ListView.Behaviors>
<behaviors:EventToCommandBehavior
EventName="ItemTapped"
Command="{Binding SurgerySelectedCommand}"
EventArgsConverter="{StaticResource ItemTappedConverter}">
</behaviors:EventToCommandBehavior>
</ListView.Behaviors>
</ListView>
I tried to use VisualStates but that was not working, because tapping the button does not actually change the SelectedItem (one would need to click the surrounding/parent grid element for that). Moreover, the altered VisualState was only applied to the Grid's BackgroundColor, not to that of the actual button.
Question: How can I highlight the current Category/Button by changing its Background Color?
Since the selection is working good, remains only the ui/xaml part, if you look at the documentation about VisualStateManager, you can add the following style:
<CollectionView.Resources>
<Style TargetType="Grid">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="LightSkyBlue" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</CollectionView.Resources>

Segmented control Xamarin Forms customisation

I would like to create the segmented control in the image below.
What i currently have or attempted using is the library in the following link : https://github.com/1iveowl/Plugin.SegmentedControl
How ever as you can see the final result ends up being a horizontal segmented UI, which is what I do not want.
I have checked the documentation of the plugin to see if there is a way of changing the orientation and it seems that is the current limitation of the plugin
<control:SegmentedControl
x:Name="SegmentedGenderControl"
TintColor="#F2EBF9"
SelectedTextColor="#6F1AC1"
TextColor="Black"
DisabledColor="White"
BorderColor="#6F1AC1"
BorderWidth="1.0"
FontSize="Medium"
Margin="8,8,8,8">
<control:SegmentedControl.Children >
<control:SegmentedControlOption Text="Male"/>
<control:SegmentedControlOption Text="Female"/>
<control:SegmentedControlOption Text="Female"/>
</control:SegmentedControl.Children>
</control:SegmentedControl>
The second alternative that I have thought about is using a grid with 3 rows :
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
And then manually handle the selection based on the selection. Is there a simpler or plugin that is available to the public that is not the one above that I can use ?
So I finally managed to solve this problem as suggested by an external party through the use of a collection view
See the code that follows :
<CollectionView
HeightRequest="250"
x:Name="OptionsCollectionView"
ItemsSource="{Binding SelectionOptions}"
VerticalOptions="Start"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<yummy:PancakeView
x:Name="optionPancake"
Padding="20">
<yummy:PancakeView.Border>
<yummy:Border
Color="{StaticResource CollectionViewBorderColor}"
Thickness="2" />
</yummy:PancakeView.Border>
<StackLayout
Orientation="Horizontal">
<Label
x:Name="optionLabel"
Text="{Binding Option}"
FontSize="15"
FontFamily="EuclidCircularASemibold"
TextColor="{StaticResource SubHeadingColor}"
FontAttributes="Bold" />
</StackLayout>
</yummy:PancakeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
The code that follows is for styling the visual state group, when an item is selected:
<Style TargetType="yummy:PancakeView">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup>
<VisualState Name="Normal"/>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter
Property="BackgroundColor"
Value="{StaticResource FrameSelectedColor}"/>
<Setter
Property="yummy:PancakeView.Border"
Value="{yummy:BorderMarkup Color={StaticResource SelectedLabelColor}, Thickness='2'}"/>
<Setter TargetName="optionLabel"
Property="Label.TextColor"
Value="{StaticResource SelectedLabelColor}"/>
<Setter Property="CornerRadius"
Value="5"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>

DataTrigger from interaction not working Windows Phone

I have simple example and databinding using TemplatedParent is not working. Does anyone have idea what is wrong?
<Button Background="Red" Content="xD">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border>
<i:Interaction.Triggers>
<ec:DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Background}" Value="Red">
<ec:ChangePropertyAction PropertyName="Background" Value="CadetBlue"/>
</ec:DataTrigger>
</i:Interaction.Triggers>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
No error in output. Background is supposed to be set to CadetBlue but no effect is applied.
It seems that RelativeSource.TemplatedParent works fine inside a template, but the triggers don't work as expected: if the trigger condition matches initially, the trigger/action doesn't fire. If you change the bound property programmatically, the trigger will fire. That's why it works with IsPressed: the button didn't start out pressed; it was pressed after it was loaded.
If you move the triggers out of the template and attach them directly to the button and adjust the bindings accordingly, everything should just work:
<Button x:Name="_button"
Background="Red"
Content="xD">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding ElementName=_button, Path=Background.Color}"
Value="Red">
<ei:ChangePropertyAction PropertyName="Background"
Value="CadetBlue" />
</ei:DataTrigger>
</i:Interaction.Triggers>
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
Note the background trigger must bind to Background.Color; it doesn't work if you bind to the brush itself, possibly because SolidColorBrush does not override Equals.

Listview Disabling item click

I am developing Windows Store App, and I have such XAML code:
<Popup x:Name="Panel3" IsOpen="False" Grid.ColumnSpan="18" Grid.Column="13" Grid.Row="4" Grid.RowSpan="31">
<StackPanel>
<Rectangle Width="765" Height="10" />
<ListView x:Name="Person" Grid.ColumnSpan="18" Grid.Column="13" HorizontalAlignment="Left" Height="643" Grid.Row="4" Grid.RowSpan="31" VerticalAlignment="Top" Width="765" >
<ListView.Background>
<SolidColorBrush Color="#FF665920" Opacity="0.85"/>
</ListView.Background>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Popup>
I want to make item selection on listview disabled. So it is for view only, users cannot select/click anything inside listview. How can i make that happen? My regards...
P.S.
I added IsItemClickEnabled="False" to listview line:
<ListView x:Name="Person" Grid.ColumnSpan="18" Grid.Column="13" HorizontalAlignment="Left" Height="643" Grid.Row="4" Grid.RowSpan="31" VerticalAlignment="Top" Width="765" IsItemClickEnabled="False">
But it did not change anything, still clickable.
You need set the SelectionMode property to None to disable the item selection of a ListView:
<ListView x:Name="Person" SelectionMode="None" ... />
additionally you may still need the IsItemClickEnabled="False" depending on your needs.
I've found you need to modify the visual state of the ListViewItem along with setting the SelectionMode="None" and IsItemClickEnabled="False" if needed, as nemesv said in his answer.
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<!-- here we are clearing the state behavior,
thus disabling the clickability of the ListViewItem -->
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver" />
<VisualState x:Name="Pressed" />
/VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid>
<ContentPresenter x:Name="ListViewItemContent" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>