在代码隐藏中创建 silverlight 边框?

发布于 2024-11-14 22:29:43 字数 937 浏览 4 评论 0原文

我在 XAML 中有以下边框:

<Border
    Grid.Column="0"
    Grid.ColumnSpan="3"
    Grid.RowSpan="3"
    CornerRadius="1,1,1,1"
    Background="Red"
    BorderBrush="#333333"
    BorderThickness="1,1,1,1"
    x:Name="border"
    RenderTransformOrigin="0.5,0.5">
    <Border.RenderTransform>
        <TransformGroup>
            <ScaleTransform />
            <SkewTransform />
            <RotateTransform />
            <TranslateTransform />
        </TransformGroup>
    </Border.RenderTransform>
    <ContentPresenter
        x:Name="contentPresenter"
        Margin="10,0,10,0"
        ContentTemplate="{TemplateBinding ContentTemplate}"
        VerticalAlignment="Center"
        HorizontalAlignment="Center" />
</Border>

并且我正在尝试在后面的代码 (C#) 中创建类似的边框。我无法超越 Border b = new Border(),我不确定应该如何将边框放在特定的网格列内或如何跨越它。

有什么想法吗?

I have the following border in XAML:

<Border
    Grid.Column="0"
    Grid.ColumnSpan="3"
    Grid.RowSpan="3"
    CornerRadius="1,1,1,1"
    Background="Red"
    BorderBrush="#333333"
    BorderThickness="1,1,1,1"
    x:Name="border"
    RenderTransformOrigin="0.5,0.5">
    <Border.RenderTransform>
        <TransformGroup>
            <ScaleTransform />
            <SkewTransform />
            <RotateTransform />
            <TranslateTransform />
        </TransformGroup>
    </Border.RenderTransform>
    <ContentPresenter
        x:Name="contentPresenter"
        Margin="10,0,10,0"
        ContentTemplate="{TemplateBinding ContentTemplate}"
        VerticalAlignment="Center"
        HorizontalAlignment="Center" />
</Border>

and I'm trying to create a similar border in code behind (C#). I can't get beyond Border b = new Border(), I'm not sure how I'm supposed to put the border inside the specific grid column or how to span it.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

━╋う一瞬間旳綻放 2024-11-21 22:29:43

像这样的事情:

var border = new Border();

Grid.SetColumn(border, 0);
Grid.SetColumnSpan(border, 3);
Grid.SetRowSpan(border, 3);

border.CornerRadius = new CornerRadius(1);
border.Background = new SolidColorBrush(Colors.Red);
border.BorderBrush = new SolidColorBrush(Color.FromArgb(0xff, 0x33, 0x33, 0x33));
border.BorderThickness = new Thickness(1);
border.RenderTransformOrigin = new Point(0.5, 0.5);

var transformGroup = new TransformGroup();
transformGroup.Children.Add(new ScaleTransform());
transformGroup.Children.Add(new SkewTransform());
transformGroup.Children.Add(new RotateTransform());
transformGroup.Children.Add(new TranslateTransform());
border.RenderTransform = transformGroup;

如果您希望我设置其余属性,请告诉我。

Something like this:

var border = new Border();

Grid.SetColumn(border, 0);
Grid.SetColumnSpan(border, 3);
Grid.SetRowSpan(border, 3);

border.CornerRadius = new CornerRadius(1);
border.Background = new SolidColorBrush(Colors.Red);
border.BorderBrush = new SolidColorBrush(Color.FromArgb(0xff, 0x33, 0x33, 0x33));
border.BorderThickness = new Thickness(1);
border.RenderTransformOrigin = new Point(0.5, 0.5);

var transformGroup = new TransformGroup();
transformGroup.Children.Add(new ScaleTransform());
transformGroup.Children.Add(new SkewTransform());
transformGroup.Children.Add(new RotateTransform());
transformGroup.Children.Add(new TranslateTransform());
border.RenderTransform = transformGroup;

Let me know if you want me to set the rest of the properties.

眉目亦如画i 2024-11-21 22:29:43

如果这可以帮助你:

            Border b = new Border();
            Grid.SetColumn(b, 0);
            Grid.SetColumnSpan(b, 3);
            Grid.SetRowSpan(b, 3);

            b.CornerRadius = new CornerRadius(1);
            b.Background = new SolidColorBrush(Colors.Red);

            // Then add your border to the grid
            g.Children.Add(b);

但是对于 ContentPresneter 我不知道该怎么做

If that can help you :

            Border b = new Border();
            Grid.SetColumn(b, 0);
            Grid.SetColumnSpan(b, 3);
            Grid.SetRowSpan(b, 3);

            b.CornerRadius = new CornerRadius(1);
            b.Background = new SolidColorBrush(Colors.Red);

            // Then add your border to the grid
            g.Children.Add(b);

But for the ContentPresneter I dont know how to do that

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文