microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.31k stars 676 forks source link

UIElement Translation and other Vector3 Properties are not DependencyProperties #2130

Closed michael-hawker closed 1 year ago

michael-hawker commented 4 years ago

Describe the bug Because these particular UIElement properties are not DependecyProperties they cannot be set in Styles which makes it difficult to configure multiple elements with the same style of course...

Steps to reproduce the bug

<ListView HorizontalAlignment="Center" VerticalAlignment="Center"
                  ItemsSource="{x:Bind Items}">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Shadow" Value="{StaticResource BackgroundGridShadow}"/>
                    <Setter Property="Translation" Value="0,0,64"/> <!-- Error Here -->
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="x:String">
                    <Border BorderBrush="Black" CornerRadius="8">
                        <TextBlock Padding="16" Text="{x:Bind}" FontWeight="SemiBold" Foreground="Black"/>
                    </Border>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

Expected behavior Able to add value to Translation in Style.

Version Info

Windows 10 version Saw the problem?
Insider Build (19584) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop
Mobile
Xbox
Surface Hub
IoT

Additional context Related Issue #938

michael-hawker commented 4 years ago

Part of this may stem from an more complex issue that you can't make an Attached Property that's of a struct type???

StephenLPeters commented 4 years ago

@codendone I think this is by design right? the translation property is a facade and I think they a purposely not DPs

michael-hawker commented 4 years ago

Even if it's a facade, there could still be a DP for the facade so that it could be styled.

codendone commented 4 years ago

These are indeed intentionally not DPs, but that requires a bit more explanation.

For several years we've been searching for ways to improve the performance of XAML. One of the places where lots of time is spent is handling of DPs. DPs are powerful, which can be great, but they also can be quite expensive due to their ability to have default values, values set by style, local values, and animated values. These options incur both memory and CPU overhead. And even properties which only get set locally pay significant cost just to set and read that local value. To reduce the cost of properties, we've been working on a new "simple property" model.

The UIElement.Translation/Scale/Rotation (and others) are amongst the first simple properties. These are far more efficient -- if I recall correctly, I believe it was at least a 10x improvement for CPU.

As you point out, we do currently have the problem that they can't be set via style. This is something we intend to fix, though we haven't yet decided on how to do that. It is possible that we may create a new type of Setter which supports simple properties. Whatever the form, this won't be until after WinUI 3.0.

I expect we'll eventually have a separate feature logged to "add style support for simple properties", but for now we can use this issue to track that.

michael-hawker commented 4 years ago

Thanks @codendone for the info and details on this!

I know there's a lot of opportunities to evolve and move things forward for XAML to improve performance, but it does make it hard for our developers if there's no stop-gap or guidance available for what they're used to doing with the platform (markup, styling, animations, etc...) and how to enable those scenarios with these new properties. Is there an easy way to identify these new types of properties in the docs (or would it just be the ones that don't have DepedencyProperty backings)?

I worked around this limitation by writing an attached property to do the 'listening' and styling aspects and just pass the value to the framework for the given property. This of course adds back the extra overhead, but at least enables this scenario for now. Maybe in the future, more could happen at compile-time for these scenarios like how x:Bind has improved performance?

In the meantime, I could add them to the Toolkit for now at least until this issue is resolved for those that don't need the high-performance throughput, but need to style a few components?

codendone commented 4 years ago

There isn't a clear way to identify which properties are the new "simple properties". Not having a matching DependencyProperty is a potential indicator, but there have been a few other properties we've added in the last few years where we haven't added a DependencyProperty when we believed that support was not needed for those specific properties. Currently this is the set of properties using the new "simple property" implementation:

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.