BartekW
Topic Author
Posts: 53
Joined: 24 Mar 2021, 14:33

Re: Getting Started with C++

08 Apr 2021, 13:00

Do u know why my ListBox displays only last item?
Are you able to reproduce this on XamlPlayer (included in the SDK) or XamlToy?
I will try do this
 
BartekW
Topic Author
Posts: 53
Joined: 24 Mar 2021, 14:33

Re: Getting Started with C++

08 Apr 2021, 13:14

@jsantos

Another question with styles and templates. To override style and template to ListBox I created Resources.xaml
And here I have
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
    <!--ListBox-->
    <ControlTemplate x:Key="Template.ListBox" TargetType="ListBox">
        <ScrollViewer Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Focusable="False">
            <ItemsPresenter />
        </ScrollViewer>
    </ControlTemplate>
    
    <Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
        <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling"/>
        <Setter Property="VirtualizingPanel.ScrollUnit" Value="Pixel"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource Template.ListBox}"/>
    </Style>

     <!--ListBoxItem--> 
    <ControlTemplate x:Key="Template.ListBoxItem" TargetType="ListBoxItem">
        <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        </Border>
    </ControlTemplate>
    
    <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"/>
        <Setter Property="Padding" Value="12,8.5"/>
        <Setter Property="Template" Value="{StaticResource Template.ListBoxItem}"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource Style.Focus.Inner.Uniform}"/>
    </Style>

</ResourceDictionary>
And in App.xaml I added that resource and my Listbox is still pink :/ Have you an idea what is wrong?

Edit. Should I provide it right? I included Resources.xaml.bin.h file and provided it. It changed a little bit but still pink style..
Edit 2. In xaml Toy it works - I created some Tags with names and it display all, so maybe its something in code. And it is omg... I used bad pointer, now it works. But there are still pink styles.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 81 guests