I have a page with content detail.
Currently now is just for single page but my friend want the detail page can be scrolled left and right like flipview control.
I am currently have some difficulties to change the View Model to become FlipView. So I want to using gesture in my content detail page.
How I can achieve flipview animation using the gesture manipulation?
What I mean with flipview animation is when scrolled left or right, I can see the previous or next item.
You can place the controls before or behind your visible item by setting their TranslateX of TraslateTransform and use the Clip proprety of the visible item.
I have build a FlipView-like control that acts like a FlipView but it can loops. Here is the xaml code:
<Style TargetType="local:LoopingBannerControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LoopingBannerControl">
<Grid x:Name="RootGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FFF0F0F0" d:DesignWidth="199.667" d:DesignHeight="215.222">
<Grid.Resources>
<Storyboard x:Name="NextStory">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="NextImageBtn">
<EasingDoubleKeyFrame x:Name="NextRightOriTranslateXFrame" KeyTime="0" Value="200"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="CurrentImageBtn">
<EasingDoubleKeyFrame x:Name="NextMiddleOriTranslateXFrame" KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame x:Name="NextMiddleTargetTranslateXFrame" KeyTime="0:0:0.3" Value="-200"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PreviousStory">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="CurrentImageBtn">
<EasingDoubleKeyFrame x:Name="PreviousMiddleOriTranslateXFrame" KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame x:Name="PreviousMiddleTargetTranslateXFrame" KeyTime="0:0:0.3" Value="200"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="PreviousImageBtn">
<EasingDoubleKeyFrame x:Name="PreviousLeftOriTranslateXFrame" KeyTime="0" Value="-200"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="ShowBtnStory">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PreviousBtn">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="NextBtn">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PreviousBtn">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.5"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="NextBtn">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.5"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="HideBtnStory">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PreviousBtn">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="NextBtn">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PreviousBtn">
<SplineDoubleKeyFrame KeyTime="0" Value="0.5"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="NextBtn">
<SplineDoubleKeyFrame KeyTime="0" Value="0.5"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Grid.Clip>
<RectangleGeometry Rect="0 0 200 200"/>
</Grid.Clip>
<Button x:Name="PreviousImageBtn" Background="{x:Null}" Padding="0" BorderThickness="0">
<Button.RenderTransform>
<CompositeTransform TranslateX="-200"/>
</Button.RenderTransform>
<Image x:Name="PreviousImage" Stretch="UniformToFill"/>
</Button>
<Button x:Name="NextImageBtn" Background="{x:Null}" Padding="0" BorderThickness="0">
<Button.RenderTransform>
<CompositeTransform TranslateX="200"/>
</Button.RenderTransform>
<Image x:Name="NextImage" Stretch="UniformToFill"/>
</Button>
<Button x:Name="CurrentImageBtn" Background="{x:Null}" Padding="0" BorderThickness="0">
<Button.RenderTransform>
<CompositeTransform/>
</Button.RenderTransform>
<Image x:Name="CurrentImage" Stretch="UniformToFill" RenderTransformOrigin="0.5,0.5"/>
</Button>
<Button x:Name="PreviousBtn" Background="#FFEAEAEA" BorderThickness="0" VerticalAlignment="Stretch" Width="25" Opacity="0" Padding="0" Visibility="Collapsed">
<TextBlock Text="<"/>
</Button>
<Button x:Name="NextBtn" Background="#FFEAEAEA" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="25" Padding="0" Opacity="0" Visibility="Collapsed">
<TextBlock Text=">"/>
</Button>
<StackPanel x:Name="IndexIndicatorSP" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The Storyboard part is the animation of switching item. You should paste it to your project to see what happens :-)
i need to create animation with images more than two images.i'm done the animation with two images as shown below. i'm beginner to this environment please help me to create the story board with five images.
in class i'm calling this method.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Storyboard1.Begin();
}
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image2" RepeatBehavior="Forever">
<DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="230"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Image Stretch="Uniform" Name="image1" Source="/Images/w1.png" />
<Image Stretch="Uniform" Name="image2" Source="/Images/w2.png" />
<!--
<Image Stretch="Uniform" Name="image3" Source="/Images/w3.png" />
<Image Stretch="Uniform" Name="image4" Source="/Images/w4.png" />
<Image Stretch="Uniform" Name="image4" Source="/Images/w5.png" />
-->
</Grid>
</Grid>
Please Help me.....
I'm guessing you just want to switch images? Kinda like a flipbook yeah?
If that is the case animating the Opacity is bad way to do it. Why not just animate the Source and switch it from w1.png to w2.png to w3.png etc?
That way you can simplified your code to basically
<Image Stretch="Uniform" Name="myImage" Source="/Images/w1.png" />
And your StoryBoard to
<Storyboard x:Name="Storyboard1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Image.Source)" Storyboard.TargetName="myImage" RepeatBehavior="Forever">
<DiscreteObjectKeyFrame KeyTime="0" Value="="/Images/w1.png"></DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:1" Value="="/Images/w2.png"></DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:2" Value="="/Images/w3.png"></DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:3" Value="="/Images/w4.png"></DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:4" Value="="/Images/w5.png"></DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
If you want to keep some weird Opacity animation, you can also add them into the StoryBoard as well.
simple noob question again. I have a windows 8 phone app with a ListBox loaded with ListBoxItems (that are just plain text). I set the foreground color of the text to white in xaml:
<ListBox x:Name="L1" Foreground="white">
Once I invoke the SelectedIndex property of ListBox, the foreground changes to red. It does this whether I set it in xaml or c#. If I try and add code in c# to change the color manually after SelectedIndex has been invoked, it still doesn't work...
tempListBoxItem = listBoxPicType.SelectedItem as ListBoxItem;
tempListBoxItem.Foreground = //some color that isn't red
what is the simplest way to get around this? TIA
It has a simple way to achieve it, you can change the ListBoxItem ControlTemplate. This is the code for details
you can put the style within the resource of the PhoneApplicationPage, change the Selected VisualState
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<!--The selected state, change the value to your color-->
<DiscreteObjectKeyFrame KeyTime="0" Value="Your Color"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ListBox
<ListBox ItemContainerStyle="{StaticResource ListBoxItemStyle1}"/>
Wish this can help you. Thanks
I have got a strange problem with the styling of my pivot control.
I edited a copy of the default template in Expression Blend because I want to remove the entire header.
The adapted style:
<Style x:Key="PivotWithoutHeader" TargetType="phone:Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:Pivot">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Background="{TemplateBinding Background}" Grid.RowSpan="3"/>
<!--<ContentControl ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" HorizontalAlignment="Left" Margin="24,17,0,-7" Style="{StaticResource PivotTitleStyle}"/>-->
<Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
<ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And the usage of my style:
<phone:Pivot Grid.Row="1" x:Name="Objects" ItemsSource="{Binding Profiles}"
Style="{StaticResource PivotWithoutHeader}">
<phone:Pivot.ItemContainerStyle>
<Style TargetType="phone:PivotItem">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</phone:Pivot.ItemContainerStyle>
<phone:Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Image Source="Resources/homer.png"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="#Sample" />
<Button Margin="347,0,0,0" Command="{Binding DataContext.SettingsCommand, ElementName=Objects}" CommandParameter="{Binding .}" />
</Grid>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
My thought was just to remove or set the visibility of <Primitives:PivotHeadersControl> to collapsed but then my app crashes without any exception and the following message in my output window: "The program '[2332] TaskHost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'" appears.
I read some posts to move up the pivot so that the header is out of the screen but I need my customized pivot at the bottom of my page with some other controls above it.
Does anybody have an idea how to remove the header?
EDIT: For clarity I want to remove title and header.
You can remove the PivotItem header on the Pivot Control by replacing the Pivot.HeaderTemplate property with a blank DataTemplate. If you're trying to remove the Title rather than the Header, then I would like to know the solution too. ^^
<phone:Pivot ItemsSource="{Binding Data}" ItemTemplate="{StaticResource CustomPivotItemTemplate}">
<phone:Pivot.HeaderTemplate>
<DataTemplate/>
</phone:Pivot.HeaderTemplate>
</phone:Pivot>
Try this one:
<UserControl.Resources>
<ResourceDictionary>
<Thickness x:Key="PivotPortraitThemePadding">0,0,0,0</Thickness>
<Thickness x:Key="PivotLandscapeThemePadding">0,0,0,0</Thickness>
<Style x:Key="PivotWithoutHeaderStyle" TargetType="Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Foreground" Value="{ThemeResource PhoneForegroundBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Pivot">
<Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Orientation">
<VisualState x:Name="Portrait">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
<DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Landscape">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
<DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="TitleContentControl" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Style="{StaticResource PivotTitleContentControlStyle}" Height="0"/>
<ScrollViewer x:Name="ScrollViewer" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="0" Grid.Row="1" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled">
<PivotPanel x:Name="Panel" VerticalAlignment="Stretch">
<PivotHeaderPanel x:Name="Header" Background="{TemplateBinding BorderBrush}" Height="0" Margin="0" Visibility="Collapsed">
<PivotHeaderPanel.RenderTransform>
<CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0"/>
</PivotHeaderPanel.RenderTransform>
</PivotHeaderPanel>
<ItemsPresenter x:Name="PivotItemPresenter">
<ItemsPresenter.RenderTransform>
<TranslateTransform x:Name="ItemsPresenterTranslateTransform" X="0"/>
</ItemsPresenter.RenderTransform>
</ItemsPresenter>
</PivotPanel>
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</UserControl.Resources>
...
<Pivot Style="{StaticResource PivotWithoutHeaderStyle}">
...
The template of the Pivot control was changed in WP8 and it now requires that the PivotHeadersControl be present in the template. (You could remove it in WP7.x)
Just have a zero height or other "empty" content in your header instead.
I'm not aware of this having been publically documented as most people who've upgraded to WP8 are using the shim to the old version of the control. However, I Noted this at the end of a blog article at http://blog.mrlacey.co.uk/2013/01/pivot-and-panorama-have-moved-and.html
So removing the header AND the title doesn't work anymore on Windows Phone 8.
So I ported an existing control from: http://www.codeproject.com/Articles/136786/Creating-an-Animated-ContentControl to Windows Phone 8.
dBlisse's solution worked for me to hide the header template but for title I played with margins and the below trick worked for me, not sure if this is a good idea, but checked on different resolutions and looks fine.
Notice the Margin="0,-39,0,0" for stack panel below:
<phone:Pivot Background="Transparent" Margin="-12,0">
<phone:Pivot.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,-39,0,0">
YOUR CONTROLS HERE
</StackPanel>
</DataTemplate>
</phone:Pivot.ItemTemplate>
<phone:Pivot.HeaderTemplate>
<DataTemplate/>
</phone:Pivot.HeaderTemplate>
</phone:Pivot>
I finally figured it out! (I'm building a Universal Windows 10 App and had the same question.)
Add a blank HeaderTemplate to your Pivot controls as dBlisse suggested:
<Pivot ItemsPanel="{StaticResource ItemsPanelTemplate1}">
<Pivot.HeaderTemplate>
<DataTemplate/>
</Pivot.HeaderTemplate>
</Pivot>
And add this template in App.xaml:
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
<Grid Margin="0,-48,0,0"/>
</ItemsPanelTemplate>
I am trying to make the slider value to be set only from data binding.I dont want users to be able to change the slider value manually. This is the snippet. any suggestions on how to do it.
<Slider x:Name="Serverslider" Value="{Binding Value}"
/>
Any attribute i am missing?
As wojtek suggests, you can use IsEnabled="False" to disable input from affecting the Slider. You get this:
Now, you have the additional requirement of needing to change the fill color of the Slider. Here you have two options:
Retemplate the Slider and change the "Disabled" visual state to look how you want it. In Blend, right-click the Slider and choose "Edit Template > Edit a Copy". Then, locate the colors you wish to change. Here, these are going to be the fill color, the Thumb Background, and the Thumb BorderBrush for the Disabled state. For example, change the following XAML:
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="HorizontalDecreaseRect">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SliderTrackDecreaseDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="HorizontalThumb">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SliderThumbDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="HorizontalThumb">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SliderThumbDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
to this:
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="HorizontalDecreaseRect">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="HorizontalThumb">
<DiscreteObjectKeyFrame KeyTime="0" Value="Orange"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="HorizontalThumb">
<DiscreteObjectKeyFrame KeyTime="0" Value="Yellow"/>
</ObjectAnimationUsingKeyFrames>
Note: Edit the parts marked "Vertical*" if you care about the vertical Slider template.
Example code: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/Slider_RetemplateDisabledState
If all Disabled Sliders in your app look the same, you can override the "theme resources" that are used to draw the Disabled Slider in your app.xaml:
<Application>
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="SliderTrackDecreaseDisabledBackgroundThemeBrush" Color="Green" />
<SolidColorBrush x:Key="SliderThumbDisabledBackgroundThemeBrush" Color="Lime" />
</ResourceDictionary>
Example Code: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/Slider_OverrideDisabledResources