如何变换边框而不变换内部内容?

时间:2019-03-04 20:14:15

标签: wpf 2d transform

这是我的问题和下面的代码的图片。我想知道如何使文本右上方翻转。以下也是我获得有关将比例转换Y设置为1的建议的链接。

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/how-to-flip-a-uielement-horizontally-or-vertically

MyImage

<Viewbox>
                <Grid>
                  <ItemsControl ItemsSource="{Binding FaceParts}">
                    <ItemsControl.ItemsPanel>
                      <ItemsPanelTemplate>
                        <Canvas Background="SlateBlue" Height="140" Width="80" />
                      </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                    <ItemsControl.ItemContainerStyle>
                      <Style TargetType="ContentPresenter">
                        <Setter Property="RenderTransform" Value="1 0 0 -1 0 0"/>
                        <Setter Property="Canvas.Left" Value="{Binding X}"/>
                        <Setter Property="Canvas.Top" Value="{Binding Y}"/>
                      </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemTemplate>
                      <DataTemplate>
                        <StackPanel>
                          <Border Width="{Binding Width}" Height="{Binding Height}" Background="{Binding Fill}" BorderBrush="Black" BorderThickness=".20">
                            <Viewbox>
                              <TextBlock Text="{Binding TextOverlay}" RenderTransformOrigin=".5,.5">
                                <TextBlock.RenderTransform>
                                  <ScaleTransform ScaleY="1"/>
                                </TextBlock.RenderTransform>
                              </TextBlock>
                            </Viewbox>
                          </Border>
                        </StackPanel>
                      </DataTemplate>
                    </ItemsControl.ItemTemplate>
                  </ItemsControl>

                  <Viewbox  VerticalAlignment="Bottom"  Height="5" Margin="0,0,0,5">
                    <TextBlock  Background="SlateBlue"  TextAlignment="Center" Text="{Binding SelectedViewerProduct.Width, Converter={StaticResource FractionConverter}}"/>
                  </Viewbox>

                </Grid>
              </Viewbox>

1 个答案:

答案 0 :(得分:1)

事实证明,将ScaleY设置为正值不会将其右侧向上翻转,为了将其右侧向上翻转,我不得不将ScaleY设置为-1。本质上,将其再次朝相反的方向翻转以使其右侧向上。

enter image description here