I want to inherit and alter the style of the default button but cannot figure out how.
Using:
<Style x:Key="MyBasicButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"></Style>
does not work, it says the "Type" cannot be used in Windows Store App project....
You can do it like this:
<Style x:Key="BaseStyle" TargetType="Button">
<Setter Property="Background" Value="Yellow" />
...
</Style>
<Style x:Key="InheritedStyle" TargetType="Button" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Foreground" Value="Red" />
...
</Style>
Related
sciChart3D WPF.
I set up the MajorTickLineStyle and applied it to the X-axis. However, the tick mark on the X-axis shows an incorrect effect.
<Style x:Key="MajorTickLineStyle" TargetType="Line">
<Setter Property="Stroke" Value="Red"/>
<Setter Property="StrokeThickness" Value="5"/>
<Setter Property="Y2" Value="20"/>
<Setter Property="X2" Value="20"/>
</Style>
<s3D:SciChart3DSurface.XAxis>
<s3D:NumericAxis3D TickTextBrush="Red" x:Name="XAxis"
FontSize="20"
FontWeight="Bold"
TickLabelAlignment="ScreenAutoRotated"
MajorTickLineStyle="{StaticResource MajorTickLineStyle}" />
</s3D:SciChart3DSurface.XAxis>
sciChart tick length incorrect effect:
The code and usage of the style is correct. It was a bug in SciChart SDK, which has already been fixed in v5.5.0.12243
I need it to implement binding in setters.
Or are there any other workarounds to be able to set binding in style setters for Windows runtime?
What kind of binding?
e.g.
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/>
Ok, then you should do something like this:
Here you can't bind a value to Padding.
<Style x:Key="GridViewItemStyle" TargetType="GridViewItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<GridViewItemPresenter Padding="{TemplateBinding Padding}"
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You can bind it that way:
<Style x:Key="GridViewItemStyle" TargetType="GridViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<GridViewItemPresenter Padding="{Binding PaddingValue}"
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I have a ListView that looks like this:
I am trying to remove the space between the items.
Setting the Margin and Padding of the ItemTemplate to zero is not working.
Setting HorizontalContentAlignment and VerticalContentAlignment to Stretch is not working.
Got it, the ItemContainerStyle must have a template with a ListViewItemPresenter where the ContentMargin is set to 0. As well as the Margin of the ItemContainerStyle must be 0.
ListView:
<ListView ItemContainerStyle="{StaticResource CustomItemContainerStyle}">
<ListView/>
Style:
<Style x:Key="CustomItemContainerStyle" TargetType="ListViewItem">
<!-- The following two styles fixes the issue of items not expanding 100%. -->
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<!-- Margin must be zero to get rid of the space between items. Default is 1.-->
<Setter Property="Margin" Value="0" />
<!-- ListViewItem styles and templates: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709921.aspx -->
<!-- ContentMargin must be zero to get rid of the vertical space between items. Defaults is 4. -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
Padding="{TemplateBinding Padding}"
SelectionCheckMarkVisualEnabled="True"
CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}"
CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}"
CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}"
SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}"
SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}"
SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}"
SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}"
SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="Stretch"
PointerOverBackgroundMargin="0"
ContentMargin="4" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Final screenshot:
I am trying to follow the article here to add a custom control to my project so that I can call it ("promptForPhotosetName") like so:
Popup popTart = new Popup();
popTart.Child = new promptForPhotosetName();
popTart.IsOpen = true;
I added a Custom Control to my project based on Templated Control.
My custom control class (which IS in the Photrax namespace) contains this constructor:
public promptForPhotosetName()
{
this.DefaultStyleKey = typeof(promptForPhotosetName);
}
I have this in \Themes\Generic.xaml, which is the other file (along with promptForPhotsetName.cs) that was created when I added the Custom Control:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Photrax">
<Style TargetType="local:promptForPhotosetName">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:promptForPhotosetName">
<StackPanel Orientation="Vertical">
<ListBox >
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="Windows 8.jpg" Height="200" Width="300" Stretch="Fill"></Image>
<Image Source="Windows_8.jpg" Height="200" Width="300" Stretch="Fill"></Image>
<Image Source="windows8(1).jpg" Height="200" Width="300" Stretch="Fill">
</Image>
</StackPanel>
</ListBoxItem>
</ListBox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Yet I get this error: The name "promptForPhotosetName" does not exist in the namespace "using:Photrax"." on both this line of XAML:
<Style TargetType="local:promptForPhotosetName">
...and this one:
<ControlTemplate TargetType="local:promptForPhotosetName">
Why? The class promptForPhotosetName IS indeed in the Photrax namespace!
Sounds like just the design tools error. Rebuilding the project should make the designer recognize the types it hasn't seen before.
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?
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 )