Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CornerRadiusFilterConverter and fix FlipView corner radius #967

Merged
merged 7 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dev/Common/Common.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)ColorConversion.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)Converters.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)LifetimeHandler.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AutoHandle.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ColorConversion.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Converters.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)LifetimeHandler.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -29,4 +31,7 @@
<Priority>1</Priority>
</Page>
</ItemGroup>
</Project>
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)Converters.idl" />
</ItemGroup>
</Project>
60 changes: 60 additions & 0 deletions dev/Common/Converters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include <pch.h>
#include <common.h>
#include "Converters.h"

CppWinRTActivatableClassWithBasicFactory(CornerRadiusFilterConverter)

CornerRadiusFilterConverter::CornerRadiusFilterConverter()
{
}

winrt::IInspectable CornerRadiusFilterConverter::Convert(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language)
{
auto radius = unbox_value<winrt::CornerRadius>(value);
auto filter = unbox_value<winrt::hstring>(parameter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this an enum? Or does that make things more complicated to author in the markup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried but looks like the auto string-enum conversion only works in style setters, and using the enum type directly in xaml didn't seem to work either.

I've added an invalid arg exception to help enforce the values.


winrt::CornerRadius result;
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
result.TopLeft = radius.TopLeft;
result.TopRight = radius.TopRight;
result.BottomRight = radius.BottomRight;
result.BottomLeft = radius.BottomLeft;

if (filter == L"Top")
{
result.BottomLeft = 0;
result.BottomRight = 0;
}
else if (filter == L"Right")
{
result.TopLeft = 0;
result.BottomLeft = 0;
}
else if (filter == L"Bottom")
{
result.TopLeft = 0;
result.TopRight = 0;
}
else if (filter == L"Left")
{
result.TopRight = 0;
result.BottomRight = 0;
}

return box_value(result);
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
}

winrt::IInspectable CornerRadiusFilterConverter::ConvertBack(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language)
{
winrt::throw_hresult(E_NOTIMPL);
}
24 changes: 24 additions & 0 deletions dev/Common/Converters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once
#include "CornerRadiusFilterConverter.g.h"

class CornerRadiusFilterConverter :
public winrt::implementation::CornerRadiusFilterConverterT<CornerRadiusFilterConverter>
{
public:
CornerRadiusFilterConverter();

winrt::IInspectable Convert(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language);

winrt::IInspectable ConvertBack(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language);
};
14 changes: 14 additions & 0 deletions dev/Common/Converters.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MU_XC_NAMESPACE
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
{

[bindable]
[WUXC_VERSION_PREVIEW]
[webhosthidden]
runtimeclass CornerRadiusFilterConverter : Windows.UI.Xaml.Data.IValueConverter
{
CornerRadiusFilterConverter();
Object Convert(Object value, Windows.UI.Xaml.Interop.TypeName targetType, Object parameter, String language);
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
Object ConvertBack(Object value, Windows.UI.Xaml.Interop.TypeName targetType, Object parameter, String language);
};

}
5 changes: 5 additions & 0 deletions dev/CommonStyles/TestUI/CornerRadiusPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@
</Grid>
<Grid Grid.Row="39" Style="{StaticResource RightColumn}" Width="200" Height="200">
<FlipView CornerRadius="6">
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
<Grid Background="Red"/>
<Grid Background="Green"/>
<Grid Background="Blue"/>
Expand Down
21 changes: 16 additions & 5 deletions dev/FlipView/FlipView_themeresources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.UI.Xaml.Controls">
xmlns:local="using:Microsoft.UI.Xaml.Controls"
xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)">

<ResourceDictionary x:Key="Default">
<Thickness x:Key="FlipViewButtonBorderThemeThickness">0</Thickness>
Expand Down Expand Up @@ -74,6 +75,8 @@
<SolidColorBrush x:Key="FlipViewButtonPressedForegroundThemeBrush" Color="#FFFFFFFF" />
</ResourceDictionary>

<local:CornerRadiusFilterConverter x:Key="CornerRadiusFilterConverter" />

<Style TargetType="FlipView">
<Setter Property="Background" Value="{ThemeResource FlipViewBackground}" />
<Setter Property="BorderThickness" Value="0" />
Expand Down Expand Up @@ -108,7 +111,8 @@
<Border x:Name="Root"
Background="{ThemeResource FlipViewNextPreviousButtonBackground}"
BorderThickness="{ThemeResource FlipViewButtonBorderThemeThickness}"
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}">
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}"
contract7Present:CornerRadius="{TemplateBinding CornerRadius}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
Expand Down Expand Up @@ -155,7 +159,8 @@
<Border x:Name="Root"
Background="{ThemeResource FlipViewNextPreviousButtonBackground}"
BorderThickness="{ThemeResource FlipViewButtonBorderThemeThickness}"
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}">
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}"
contract7Present:CornerRadius="{TemplateBinding CornerRadius}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
Expand Down Expand Up @@ -202,7 +207,8 @@
<Border x:Name="Root"
Background="{ThemeResource FlipViewNextPreviousButtonBackground}"
BorderThickness="{ThemeResource FlipViewButtonBorderThemeThickness}"
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}">
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}"
contract7Present:CornerRadius="{TemplateBinding CornerRadius}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
Expand Down Expand Up @@ -248,7 +254,8 @@
<Border x:Name="Root"
Background="{ThemeResource FlipViewNextPreviousButtonBackground}"
BorderThickness="{ThemeResource FlipViewButtonBorderThemeThickness}"
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}">
BorderBrush="{ThemeResource FlipViewNextPreviousButtonBorderBrush}"
contract7Present:CornerRadius="{TemplateBinding CornerRadius}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
Expand Down Expand Up @@ -315,6 +322,7 @@
Template="{StaticResource HorizontalPreviousTemplate}"
Width="20"
Height="36"
contract7Present:CornerRadius="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusFilterConverter}, ConverterParameter='Right'}"
IsTabStop="False"
UseSystemFocusVisuals="False"
HorizontalAlignment="Left"
Expand All @@ -323,6 +331,7 @@
Template="{StaticResource HorizontalNextTemplate}"
Width="20"
Height="36"
contract7Present:CornerRadius="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusFilterConverter}, ConverterParameter='Left'}"
IsTabStop="False"
UseSystemFocusVisuals="False"
HorizontalAlignment="Right"
Expand All @@ -331,6 +340,7 @@
Template="{StaticResource VerticalPreviousTemplate}"
Width="36"
Height="20"
contract7Present:CornerRadius="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusFilterConverter}, ConverterParameter='Bottom'}"
IsTabStop="False"
UseSystemFocusVisuals="False"
HorizontalAlignment="Center"
Expand All @@ -339,6 +349,7 @@
Template="{StaticResource VerticalNextTemplate}"
Width="36"
Height="20"
contract7Present:CornerRadius="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusFilterConverter}, ConverterParameter='Top'}"
IsTabStop="False"
UseSystemFocusVisuals="False"
HorizontalAlignment="Center"
Expand Down
20 changes: 17 additions & 3 deletions dev/FlipView/TestUI/FlipViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="12">
<FlipView Width="200" Height="200">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="12">
<FlipView Width="200" Height="200"
CornerRadius="2">
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
<Grid Background="Red"/>
<Grid Background="Green"/>
<Grid Background="Blue"/>
</FlipView>
</Grid>

<FlipView Width="200" Height="200"
Margin="0, 20, 0, 0"
CornerRadius="2">
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
<Grid Background="Red"/>
<Grid Background="Green"/>
<Grid Background="Blue"/>
</FlipView>
</StackPanel>
</local:TestPage>