【问题标题】:wpf usercontrol, border cornerradius not workingwpf usercontrol,边框角半径不起作用
【发布时间】:2017-05-06 11:21:08
【问题描述】:

我有一个被边框控件包围的用户控件。我想要的是在放置控件时可以通过属性设置边框。我可以设置边框的颜色,但问题是圆角半径不起作用。它工作的唯一方法是如果我在用户控件本身中设置边框画笔。 其他一切都工作得很好。我可以设置标签的文本属性和图像的图像属性,但我无法找出角半径不起作用的原因。

    <UserControl x:Class="CoinManager.Controls.AltCoinButton"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:CoinManager.Controls"
         mc:Ignorable="d" 
         d:DesignHeight="80" Width="80">
<Border Name="crtBorder" 
        BorderThickness="1" 
        Padding="5"
        CornerRadius="5"    
        BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}">
    <Grid>
            <StackPanel HorizontalAlignment="Center">
                <Image Source="{Binding Path=ImageSource, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}" 
               Height="25" Width="25"
               />
                <Label Content="{Binding Path=ContentCoinType, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}"
                Foreground="#FAFAFA"
                HorizontalContentAlignment="Center" Margin="0,5,0,0"
               FontFamily="Segoe UI"/>
                <Label Content="{Binding Path=ContentCoinValue, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}"
               Foreground="#FAFAFA"
               HorizontalContentAlignment="Center" Margin="0,-10,0,0"
               FontFamily="Segoe UI"/>
            </StackPanel>
        </Grid>
</Border>

这是我的自定义项目中的代码。

    <Controls:AltCoinButton x:Name="btcButton"
        Height="80"
        Width="80" ImageSource="{StaticResource BtcLogo}"
        BorderBrush="#FF9900" 
        ContentCoinType="Bitcoin" 
        ContentCoinValue="€ 1544,23" 
        HorizontalAlignment="Left" 
        Margin="186,50.254,0,0" 
        VerticalAlignment="Top" d:LayoutOverrides="Width, Height"/>

谁能帮帮我?

【问题讨论】:

  • 请删除这个问题。

标签: c# wpf xaml user-controls


【解决方案1】:

我找到了解决方案。原来我为边界刷源实现了错误的相对关系。而不是:

    BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}">

应该是:

    BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 2012-06-02
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多