[英]wpf usercontrol, border cornerradius not working
我有一個用bordercontrol包圍的usercontrol。 我想要的是在放置控件時可以通過屬性設置邊框刷。 我可以設置邊框的顏色,但是問題是角半徑不起作用。 唯一可行的方法是,如果我在用戶控件本身中設置了borderbrush。 其他一切都很好。 我可以設置標簽的文本屬性和圖像的圖像屬性,但是我無法找出為什么角半徑不起作用。
<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"/>
你們中有人可以幫我嗎?
我找到了解決方案。 事實證明,我為方差畫筆源實現了錯誤的相對關系。 代替:
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}">
應該是:
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.