【问题标题】:How to bind individual Border CornerRadius?如何绑定单个 Border CornerRadius?
【发布时间】:2017-12-08 00:27:32
【问题描述】:

我用Border 做了一个圆窗这样的:

<Border CornerRadius="{Binding WindowCornerRadius}" Background="{StaticResource BackgroundDarkBrush}">
    <Border.Effect>
        <DropShadowEffect ShadowDepth="0" Opacity="0.2"></DropShadowEffect>
    </Border.Effect>
</Border>
<Grid>
    <Grid.RowDefinitions>
        <!--Title Bar-->
        <RowDefinition Height="{Binding TitleHeightGridLength}"></RowDefinition>
        <RowDefinition Height="auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <!--Title Bar-->
    <Border Background="{StaticResource TitleBrush}" CornerRadius="{Binding WindowCornerRadius,WindowCornerRadius,0,0}">
        <Grid Grid.Column="0" Panel.ZIndex="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Button Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
                <Image Source="Images/Logo/Wink.png"></Image>
            </Button>
        </Grid>
    </Border>
</Grid>
</Grid>
</Border>

如您所见,我更改了第一个 GridRow 的背景,这阻止了它是圆形的(具有圆角半径),我想更正它为第一个 GridRow 添加边框但我失败了。上面的代码在CornerRadius="{Binding WindowCornerRadius,WindowCornerRadius,0,0}" 中给了我错误:

“Binding”类型的构造函数没有 4 个参数。

我的问题是我添加另一个边框是否正确? (如果是,我如何单独绑定CornerRadius)。

【问题讨论】:

    标签: wpf


    【解决方案1】:

    您不能使用这样的绑定。 CornerRadius 上的绑定将从您的 DataContext 中查找 Thickness 类型的属性,并在绑定中给出 Path。路径隐含在绑定中,但您可以明确设置它:Property="{Binding Path=blabla}"。更多信息here

    CornerRadius 会动态变化吗?为什么?

    也看看这个: Binding only part of the margin property of WPF control

    【讨论】:

    • 价值转换器似乎是正确的解决方案!?
    • 是的,实现你自己的转换器,它只复制原始 4 个厚度属性的一部分
    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2011-08-26
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2016-02-28
    相关资源
    最近更新 更多