Reputation: 1653
I want to add custom controls, like a slider bar or a button in the secondary section of the app bar in windows phone 8.1, like the one in the app bar of camera app.
Any idea how to do it?
Upvotes: 3
Views: 587
Reputation: 255
So, it appears, that my solution works only in designer, tried another, but which also only worked in designer. So I would conclude that it is impossible to put in commandbar anything other than default buttons, my attempts were as following:
I tried to apply this style to AppbarButoon, button changed to slider in designer, but on the phone it style has been overriden
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{ThemeResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{ThemeResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{ThemeResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}"/>
<Setter Property="FontWeight" Value="{ThemeResource PhoneButtonFontWeight}"/>
<Setter Property="FontSize" Value="{ThemeResource TextStyleLargeFontSize}"/>
<Setter Property="Padding" Value="9.5,0"/>
<Setter Property="MinHeight" Value="{ThemeResource PhoneButtonMinHeight}"/>
<Setter Property="MinWidth" Value="{ThemeResource PhoneButtonMinWidth}"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="Grid" Background="Transparent">
<Slider ValueChanged="RangeBase_OnValueChanged" Width="100" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Second approach was to derive from slider and implement ICommandBarElement, it seemed to be working untill I run it under emulator, Slider didn't even showed up.
public sealed class CommandBarSlider : Slider, ICommandBarElement
{
public CommandBarSlider()
{
this.DefaultStyleKey = typeof(Slider);
}
public bool IsCompact { get; set; }
}
The obvious conclusion to be drawn from these codes is that what you're trying to do is either impossible, or I've overlooked something.
(Probably I've overlooked something )
Upvotes: 2