In Windows 8 app I have construction like this:
<ScrollViewer HorizontalScrollMode="Disabled">
<Grid>
<TextBlock/>
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<TextBlock/>
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<TextBlock/>
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</Grid>
</ScrollViewer>
And I need to handle scrolling by ScrollViewer (now each ListBox handle it). It's possible without adding IsEnabled="false"?
add this resource into your ScrollViewer and this should solve your issue:
<ScrollViewer.Resources>
<Style TargetType="{x:Type ListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<ItemsPresenter></ItemsPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ScrollViewer.Resources>
this way you eliminate ScrollViewer which is normally part of ListBox template
Related
I would like to change ComboBox placeholder color in my demo UWP app. So I tried to create static resources:
<UserControl.Resources>
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<ContentControl x:Name="PlaceholderTextContentPresenter"
Content="{TemplateBinding PlaceholderText}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
Using:
<ComboBox Grid.Row="1" Foreground="White" HorizontalAlignment="Stretch" Background="Transparent"
PlaceholderText="Выбор оператора" Style="{StaticResource ComboBoxStyle}">
<x:String>iPhone 11</x:String>
<x:String>iPhone 12</x:String>
<x:String>Xiaomi Red Mi</x:String>
<x:String>Samsung Galaxy 10</x:String>
<ComboBox.Resources>
<Style TargetType="ContentControl">
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
</Style>
</ComboBox.Resources>
</ComboBox>
Foreground in placeholder changed correctly but ComboBox is disappeared. How can I will change ComboBox placeholder foreground?
How to change ComboBox placeholder foreground in UWP
UWP ComboBox contains PlaceholderForeground propety, if you want to chage the default one, you just need to give it specific value like the following. And please not the property avaiable in version 16299 or higher.
<ComboBox
Grid.Row="1"
HorizontalAlignment="Stretch"
Background="Transparent"
Foreground="White"
PlaceholderText="Выбор оператора"
PlaceholderForeground="DarkBlue">
<x:String>iPhone 11</x:String>
<x:String>iPhone 12</x:String>
<x:String>Xiaomi Red Mi</x:String>
<x:String>Samsung Galaxy 10</x:String>
</ComboBox>
I'm building a custom XAML control for a UWP app that relies heavily on a ScrollViewer with snap points.
I would really like the content that is bound to the control to be virtualized, so I'm using an ItemsControl. However, when I use a VirtualizingStackPanel in the ItemsControl, and then call ChangeView() on the ScrollViewer to a specific HorizontalOffset, the animation effect when scrolling to the new offset is disabled (it just jumps directly to the offset). If I simply replace the VirtualizingStackPanel with a StackPanel (no virtualization), the horizontal animations work.
Question: Does anyone know how to use a VirtualizingStackPanel and enable horizontal animations when changing the offset?
Here is the C# adjusting the horizontal offset (the customScrollViewer is being accessed via tree-crawling, since it is part of the ControlTemplate style):
customScrollViewer.ChangeView(500, null, null, false);
And here is the XAML style for the ItemsControl:
<Style x:Key="ItemsControlSnapStyle" TargetType="ItemsControl">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer
x:Name="customScrollViewer"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalSnapPointsType="Mandatory">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Thanks!
Great question, I could reproduce this behavior, and it looks by-design. Derive from VirtualizingStackPanel document. It can only be used to display items in an ItemsControl. Generally. At the remarks part, Starting in Windows 8.1, ItemsStackPanel is used as the default ItemsPanel for ListView. If you modify the ItemsPanel, we recommend you use ItemsStackPanel or ItemsWrapGrid instead of VirtualizingStackPanel or WrapGrid.
If we replace VirtualizingStackPanel with ItemsStackPanel, and ChangeView method could work with animation. And ItemsStackPanel also support virtualizes. So we suggest you could use ItemsStackPanel as ItemsPanel for the ItemsControl.
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
I am trying to create a header template for a GroupBox (for now, and others later on).
Currently I have
<!--GroupBox-->
<Style TargetType="GroupBox">
<Setter Property="BorderBrush" Value="{StaticResource wspCharcoalDarkBrush}"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Style="{StaticResource wspTitleBlockBold}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Which works well if I have
<GroupBox Margin="3" Header="TEST">
</GroupBox>
The Header says "TEST"
If I want to customise it for a one off and use this
<GroupBox Margin="3">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Image/>
<TextBlock Text="TEST"/>
</StackPanel>
</GroupBox.Header>
</GroupBox>
All I get for a header is "System.Windows.Controls.StackPanel" in the header.
Is there a way around this so that I can have the option of specifying the header either way and not have to create 2 separate styles?
Thanks,
Brent
I have tried to create a Style to apply to any Page (like a Master Style) to include a little watermark in a corner, but this kind of style doesn't work.
<Style x:Key="WatermarkPageStyle" TargetType="Page">
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="Page">
<Grid>
<ContentPresenter/>
<TextBlock TextAlignment="Right" VerticalAlignment="Bottom" FontSize="25" Foreground="Blue" Text="Watermark"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
What's the problem? Is there a workaround?
Microsoft employee says that this is a known issue and you should set these values locally.
I want to disable the EntrenceThemeAnimation for one of my elements. I have a Grid that sets this animation to all it's children(I think it's default for a page). Is it possible to disable this animation for a ContentControl that is a children of this grid?
I've tried the following but it does not seem to work.
Content
<Grid Style="{StaticResource LayoutRootStyle}">
...
<!-- no animations for this element -->
<ContentControl x:Name="Background" Content="Tabstagram" Margin="0" Grid.Row="1" Style="{StaticResource Background}">
<ContentControl.Transitions>
<TransitionCollection/>
</ContentControl.Transitions>
<ContentControl.ContentTransitions>
<TransitionCollection/>
</ContentControl.ContentTransitions>
</ContentControl>
Styles
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Background" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid>
<Grid.ChildrenTransitions>
<TransitionCollection/>
</Grid.ChildrenTransitions>
<Grid.Transitions>
<TransitionCollection/>
</Grid.Transitions>
<Rectangle IsHitTestVisible="False" StrokeThickness="75" Margin="0" Fill="#FFC1C1C1"/>
I have the following in the LayoutRoot grid for my page and it correctly disables the entrance theme transition:
<Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootStyle}">
<Grid.ChildrenTransitions>
<TransitionCollection/>
</Grid.ChildrenTransitions>
Notice, though, that I'm overriding the transitions for a panel that's using LayoutRootStyle and I'm doing it in the page rather than a resource.
It could be that these animations flow downward from the first control they're enabled on regardless of whether or not child controls have them disabled. You could try putting both panels at the same level of the UI hierarchy (peers rather than one nested inside the other) and see if that fixes it.