C# 圆边堆垛板

C# 圆边堆垛板,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我正在开发一个windows phone 8应用程序,我有一个StackPanel的Border,但是StackPanel没有剪切到Border <Border Grid.Column="1" BorderThickness="3" BorderBrush="Black" CornerRadius="50"> <StackPanel Width="425"> <StackPanel.Ba

我正在开发一个windows phone 8应用程序,我有一个
StackPanel
Border
,但是
StackPanel
没有剪切到
Border

            <Border Grid.Column="1" BorderThickness="3" BorderBrush="Black" CornerRadius="50">
            <StackPanel Width="425">
                <StackPanel.Background>
                    <SolidColorBrush Color="#FFFBEAEA" Opacity="0.25"/>
                </StackPanel.Background>
                <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" TextWrapping="Wrap" Margin="12,0,12,6" Foreground="Black"/>
                <TextBlock Text="{Binding Type}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Foreground="Black"/>
                <TextBlock Text="{Binding Text}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiLight}" Foreground="Black"/>
            </StackPanel>
            </Border>

我不知道为什么我在网上做了一些挖掘,但这不起作用

有人能帮我吗?
谢谢。

不要使用
cliptobunds
OpacityMask
,尝试使用径向渐变作为附加
边框
元素的背景

样品

<Grid Width="256" Height="256">
<Border CornerRadius="16" Background="Black" Margin="4">
  <Border Background="Gray" Margin="32">
    <TextBlock Foreground="Black" Text="1" FontFamily="Trebuchet MS" FontSize="96pt"
               HorizontalAlignment="Center" VerticalAlignment="Center"/>
  </Border>
</Border>
<Border CornerRadius="16" Margin="4">
  <Border.Background>
    <RadialGradientBrush>
      <RadialGradientBrush.Transform>
        <TransformGroup>
          <ScaleTransform ScaleX="3" ScaleY="2" CenterX="128" CenterY="128"/>
          <TranslateTransform Y="-235"/>
        </TransformGroup>
      </RadialGradientBrush.Transform>
      <GradientStop Color="White" Offset="0"/>
      <GradientStop Color="Transparent" Offset="1"/>
    </RadialGradientBrush>
  </Border.Background>
</Border>
<Border CornerRadius="16" BorderThickness="8" BorderBrush="Black"/>


不要使用
cliptobunds
OpacityMask
,尝试使用径向渐变作为附加
边框
元素的背景

样品

<Grid Width="256" Height="256">
<Border CornerRadius="16" Background="Black" Margin="4">
  <Border Background="Gray" Margin="32">
    <TextBlock Foreground="Black" Text="1" FontFamily="Trebuchet MS" FontSize="96pt"
               HorizontalAlignment="Center" VerticalAlignment="Center"/>
  </Border>
</Border>
<Border CornerRadius="16" Margin="4">
  <Border.Background>
    <RadialGradientBrush>
      <RadialGradientBrush.Transform>
        <TransformGroup>
          <ScaleTransform ScaleX="3" ScaleY="2" CenterX="128" CenterY="128"/>
          <TranslateTransform Y="-235"/>
        </TransformGroup>
      </RadialGradientBrush.Transform>
      <GradientStop Color="White" Offset="0"/>
      <GradientStop Color="Transparent" Offset="1"/>
    </RadialGradientBrush>
  </Border.Background>
</Border>
<Border CornerRadius="16" BorderThickness="8" BorderBrush="Black"/>


不幸的是,如果不剪切内容,它的工作方式与您看到的一样

不幸的是,没有一个简单的“设置属性”解决方案(从Avalon->WPF->Silverlight->Windows Phone的第一天起就是如此)。然而,有一些解决办法,有些不太可取:

更改用户界面 许多开发人员所做的一件事就是更改UI设计我当然用过这种方法。在现代风格的Windows应用程序中,很少看到圆形容器

或者,增加内部内容的填充,这样就不会发生剪切

构建剪裁路径 但是,如果这不起作用,则需要准确地设置边框的
Clip
属性。这方面的挑战是,必须将
剪辑
指定为
路径
,这并不容易做到,尤其是当边框半径和内容大小发生变化时。虽然无法准确地插入代码,但是可以在Silverlight库(最初由Expression Blend团队创建)中找到创建和处理剪裁遮罩所需更改的最佳示例:

该文件名为
ClippingBehavior.cs
()。虽然在任何现有的Windows Phone库中都没有可直接派生和使用的
行为
类,但您应该能够遵循它执行的逻辑。它跟踪大小更改,并最终创建正确定义的剪裁遮罩,然后在附着的边框上设置该遮罩。它实际上并不是很多代码,而且非常简单。我不打算在这里复制代码,但基本上它会创建一个
PathGeometry
,然后开始创建正确的路径:

PathGeometry geometry = new PathGeometry();
    PathFigure figure = new PathFigure();
    geometry.Figures.Add(figure);

    figure.StartPoint = new Point(bounds.Left + radius.TopLeft, bounds.Top);
    figure.Segments.Add(new LineSegment() {
    Point = new Point(bounds.Right - radius.TopRight, bounds.Top),
});
/* more code follows == see original file for details */
最后,它关闭图形并设置
剪辑
属性:

figure.IsClosed = true;
this.AssociatedObject.Clip = geometry;

不幸的是,如果不剪切内容,它的工作方式与您看到的一样

不幸的是,没有一个简单的“设置属性”解决方案(从Avalon->WPF->Silverlight->Windows Phone的第一天起就是如此)。然而,有一些解决办法,有些不太可取:

更改用户界面 许多开发人员所做的一件事就是更改UI设计我当然用过这种方法。在现代风格的Windows应用程序中,很少看到圆形容器

或者,增加内部内容的填充,这样就不会发生剪切

构建剪裁路径 但是,如果这不起作用,则需要准确地设置边框的
Clip
属性。这方面的挑战是,必须将
剪辑
指定为
路径
,这并不容易做到,尤其是当边框半径和内容大小发生变化时。虽然无法准确地插入代码,但是可以在Silverlight库(最初由Expression Blend团队创建)中找到创建和处理剪裁遮罩所需更改的最佳示例:

该文件名为
ClippingBehavior.cs
()。虽然在任何现有的Windows Phone库中都没有可直接派生和使用的
行为
类,但您应该能够遵循它执行的逻辑。它跟踪大小更改,并最终创建正确定义的剪裁遮罩,然后在附着的边框上设置该遮罩。它实际上并不是很多代码,而且非常简单。我不打算在这里复制代码,但基本上它会创建一个
PathGeometry
,然后开始创建正确的路径:

PathGeometry geometry = new PathGeometry();
    PathFigure figure = new PathFigure();
    geometry.Figures.Add(figure);

    figure.StartPoint = new Point(bounds.Left + radius.TopLeft, bounds.Top);
    figure.Segments.Add(new LineSegment() {
    Point = new Point(bounds.Right - radius.TopRight, bounds.Top),
});
/* more code follows == see original file for details */
最后,它关闭图形并设置
剪辑
属性:

figure.IsClosed = true;
this.AssociatedObject.Clip = geometry;

请您尝试将背景设置为边框而不是stackpanel。几乎所有的背景都是一样的

<Border.Background>
==set what type of background u want==
  </Border.Background>
<StackPanel Width="425">

            <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" TextWrapping="Wrap" Margin="12,0,12,6" Foreground="Black"/>
            <TextBlock Text="{Binding Type}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Foreground="Black"/>
            <TextBlock Text="{Binding Text}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiLight}" Foreground="Black"/>
        </StackPanel>

==设置您想要的背景类型==

请您尝试将背景设置为边框而不是stackpanel。几乎所有设置都相同

<Border.Background>
==set what type of background u want==
  </Border.Background>
<StackPanel Width="425">

            <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" TextWrapping="Wrap" Margin="12,0,12,6" Foreground="Black"/>
            <TextBlock Text="{Binding Type}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Foreground="Black"/>
            <TextBlock Text="{Binding Text}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiLight}" Foreground="Black"/>
        </StackPanel>

==设置您想要的背景类型==

我从你那里得到了这个极好的答案


我从你那里得到了这个极好的答案



我认为设置“ClipToBounds”或将“Clip”属性设置为边框的矩形不起作用?我认为设置“ClipToBounds”或将“Clip”属性设置为边框的矩形不起作用?这将如何剪裁
堆栈面板的内容?您的示例没有
StackPanel
?@wiredPairie,它是一个关于如何剪裁控件的示例。我给出了一个TextBlock示例。您的答案也不会剪辑StackPanel的内容。
clip
将剪辑任何内容,这正是我所建议的。它适用于StackPanel或任何控件。嵌套
边框
s不会。这不是一个通用的解决方案——为了实现这一点,您必须对UI进行大量调整